#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x),end(x)
#define both(x) x.first,x.second
signed main()
{
int N,R,rank;
cin >> N >> R >> rank;
vector<int> ranks(2*N-1);
for(auto &&i : ranks) cin >> i;
// will eventually have the top half (excluding the best) cycle around, and the worst half (excluding middle)
// be stationary
// lower numbers move
// if rank == 1: any works, return N
if(rank == 1) {cout << N << "\n"; exit(0);}
// just simulate all the positions
int minend = INT_MAX;
int position = -1;
for(int pos = 2*N-2; pos >= 0; pos-=2)
{
vector<pair<int,int>> people;
for(int i = 0; i < 2*N-1;)
{
if(i==pos) people.push_back({ranks[i++],rank});
else people.push_back({ranks[i++],ranks[i++]});
}
for(int i = 0; i < R; i++)
{
vector<pair<int,int>> people2(people.size());
people2.back() = {max(both(people[0])),max(both(people.back()))};
people2[0] = {min(both(people[0])),min(both(people[1]))};
for(int i = 1; i < people.size()-1; i++)
{
people2[i] = {max(both(people[i])),min(both(people[i+1]))};
}
people = people2;
}
int r = 0;
for(; people[r].first!=rank && people[r].second != rank;r++);
if(r < minend)
{
minend = r;
position = pos/2+1;
}
}
cout << position << "\n";
// no.2 always moves to pos1, until 1 arrives, then cycles
// unless it starts with 1, then it waits once first
// no.3 always moves to pos1, until 2 or 1 arrives, then cycles
// waits with starting until neither 1 nor 2 is at its position
// can be complicated if (2 1) (3 ...)
// as 1 moves up, and 3 comes to 2: (2 3) (...)
// next, 2 moves up
}
Compilation message
archery.cpp: In function 'int main()':
archery.cpp:28:54: warning: operation on 'i' may be undefined [-Wsequence-point]
28 | else people.push_back({ranks[i++],ranks[i++]});
| ~^~
archery.cpp:35:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 1; i < people.size()-1; i++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2068 ms |
212 KB |
Time limit exceeded |
4 |
Execution timed out |
2069 ms |
368 KB |
Time limit exceeded |
5 |
Correct |
2 ms |
212 KB |
Output is correct |
6 |
Execution timed out |
2079 ms |
212 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
2036 ms |
212 KB |
Time limit exceeded |
3 |
Execution timed out |
2058 ms |
340 KB |
Time limit exceeded |
4 |
Execution timed out |
2060 ms |
724 KB |
Time limit exceeded |
5 |
Execution timed out |
2057 ms |
6584 KB |
Time limit exceeded |
6 |
Execution timed out |
2061 ms |
212 KB |
Time limit exceeded |
7 |
Execution timed out |
2027 ms |
212 KB |
Time limit exceeded |
8 |
Execution timed out |
2051 ms |
724 KB |
Time limit exceeded |
9 |
Execution timed out |
2085 ms |
1104 KB |
Time limit exceeded |
10 |
Execution timed out |
2082 ms |
340 KB |
Time limit exceeded |
11 |
Execution timed out |
2064 ms |
1108 KB |
Time limit exceeded |
12 |
Execution timed out |
2064 ms |
340 KB |
Time limit exceeded |
13 |
Execution timed out |
2078 ms |
4800 KB |
Time limit exceeded |
14 |
Execution timed out |
2064 ms |
468 KB |
Time limit exceeded |
15 |
Execution timed out |
2077 ms |
1440 KB |
Time limit exceeded |
16 |
Correct |
94 ms |
300 KB |
Output is correct |
17 |
Execution timed out |
2068 ms |
340 KB |
Time limit exceeded |
18 |
Execution timed out |
2074 ms |
340 KB |
Time limit exceeded |
19 |
Execution timed out |
2067 ms |
316 KB |
Time limit exceeded |
20 |
Execution timed out |
2076 ms |
468 KB |
Time limit exceeded |
21 |
Execution timed out |
2054 ms |
1108 KB |
Time limit exceeded |
22 |
Execution timed out |
2071 ms |
1488 KB |
Time limit exceeded |
23 |
Execution timed out |
2072 ms |
6972 KB |
Time limit exceeded |
24 |
Correct |
50 ms |
212 KB |
Output is correct |
25 |
Execution timed out |
2064 ms |
340 KB |
Time limit exceeded |
26 |
Execution timed out |
2074 ms |
472 KB |
Time limit exceeded |
27 |
Execution timed out |
2070 ms |
1080 KB |
Time limit exceeded |
28 |
Execution timed out |
2069 ms |
4984 KB |
Time limit exceeded |
29 |
Execution timed out |
2084 ms |
340 KB |
Time limit exceeded |
30 |
Execution timed out |
2084 ms |
476 KB |
Time limit exceeded |
31 |
Execution timed out |
2083 ms |
1104 KB |
Time limit exceeded |
32 |
Execution timed out |
2077 ms |
6716 KB |
Time limit exceeded |
33 |
Correct |
70 ms |
212 KB |
Output is correct |
34 |
Execution timed out |
2078 ms |
212 KB |
Time limit exceeded |
35 |
Execution timed out |
2085 ms |
360 KB |
Time limit exceeded |
36 |
Execution timed out |
2079 ms |
336 KB |
Time limit exceeded |
37 |
Execution timed out |
2083 ms |
980 KB |
Time limit exceeded |
38 |
Execution timed out |
2078 ms |
1232 KB |
Time limit exceeded |
39 |
Execution timed out |
2080 ms |
212 KB |
Time limit exceeded |
40 |
Execution timed out |
2087 ms |
212 KB |
Time limit exceeded |
41 |
Execution timed out |
2073 ms |
340 KB |
Time limit exceeded |
42 |
Execution timed out |
2078 ms |
340 KB |
Time limit exceeded |
43 |
Execution timed out |
2087 ms |
444 KB |
Time limit exceeded |
44 |
Execution timed out |
2076 ms |
596 KB |
Time limit exceeded |
45 |
Execution timed out |
2045 ms |
1104 KB |
Time limit exceeded |
46 |
Execution timed out |
2080 ms |
1108 KB |
Time limit exceeded |
47 |
Execution timed out |
2080 ms |
7672 KB |
Time limit exceeded |