consul

Time limit: 0.1s Memory limit: 64MB Input: Output:

In Reme, a consular election is being held. This election has N electors, each of which can vote with one of the 1 000 000 0001 \ 000 \ 000 \ 000 different candidates. A candidate is considered a winner if she wins strictly more than one third of the vote (this happens because Reme elects two consuls each year). Now, you are an aspiring vote-rigger. In order to more effectively rig the vote, you need to know at least one prospective winner. Unfortunately, although each elector has cast their vote, it is not public — at least not without a price. Moreover, the old consuls, who have already counted votes, can tell you the number of votes a particular candidate won — again, at a price.

More formally, you are asked to consider a hidden sequence vv of NN integers v1,vNv_1, \dots v_N, with values at least 00 and less than 1 000 000 0001 \ 000 \ 000 \ 000. You can perform two types of queries on this sequence:

  • you can find out the value of a particular element viv_i in the sequence
  • you can see how many times a particular value xx appears in the sequence.

You are asked to find a value xx that appears strictly more than N/3N/3 times in the sequence, while making the number of queries you perform small enough.

Task

Given NN, find out any winner of the election, using the given queries, or announce that no winner exists.

Interaction

This is an interactive task. Thus the contestant will interact with the following functions, after including the file grader.h. The contestant must implement a function void solve(int N), where the parameter represents the NN from the problem statement, which must solve an instance of the task (note that in one run of the source code, this function may be called multiple times). In order to solve the task, the contestant may use the following functions:

  • int kth(int i) — which will return the value of viv_i
  • int cnt(int x) — which will return the frequency of xx in the array vv
  • void say_answer(int a) — which, if aa is at least 00 and less than 1 000 000 0001 \ 000 \ 000 \ 000, signals that aa is aa winner of the election; and if aa is 1-1, that no winner exists. If there exists a winner, and aa is not equal to a winner of the election, or if there is no winner, but aa is not 1-1, or aa is neither a valid candidate nor 1-1, then the contestant’s solution will get verdict “Wrong Answer!”.

Restrictions

Subtask Score Restrictions
1 15 points N50N \leq 50
2 another 20 points N100N \leq 100
3 another 65 points N1 000N \leq 1 \ 000

Scoring

Let QQ be the maximum number of queries made in any test case in a file (not including the call of say_answer).

Subtask 1:

  • If Q50Q \leq 50, then you will receive 100%100\% of the points on the test case.
  • If Q>50Q > 50, then you will receive 0%0\% of the points on the test case.

Subtask 2:

  • If Q60Q \leq 60, then you will receive 100%100\% of the points on the test case.
  • If 60<Q11060 < Q \leq 110, then you will receive (2202Q)%(220-2Q)\% of the points on the test case.
  • If Q>110Q > 110, then you will receive 0%0\% of the points on the test case.

Subtask 3:

  • If Q60Q \leq 60, then you will receive 100%100\% of the points on the test case.
  • If 60<Q60 < Q then you will receive (0.9(Q60)100)%(0.9^{(Q-60)} \cdot 100)\% of the points on the test case.

NOTE: the number of test cases is at most 16 00016 \ 000

Log in or sign up to be able to send submissions!