#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>ii;
vector<int>as;
int encontrar_diamond(int l,int r,ii left,ii right){
if(l>r){
return -1;
}
int mi=(l+r)/2;
as=ask(mi);
pair<int,int>c;
c=ii(as[0],as[1]);
if(c==ii(0,0)){
return mi;
}
if(l==r){
return -1;
}
int re=-1;
if(c.first>0 and c!=left){
re=encontrar_diamond(l,mi-1,left,c);
}
if(re==-1 and c.second>0 and c!=right){
re=encontrar_diamond(mi+1,r,c,right);
}
return re;
}
int find_best(int n) {
int ans=encontrar_diamond(0,n-1,ii(-1,-1),ii(-1,-1));
return ans;
}
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;
vector<int> ask(int i) {
query_count++;
if(query_count > max_q) {
cerr << "Query limit exceeded" << endl;
exit(0);
}
if(i < 0 || i >= n) {
cerr << "Bad index: " << i << endl;
exit(0);
}
vector<int> res(2);
res[0] = rank_count[g[i] - 1][i + 1];
res[1] = rank_count[g[i] - 1][n] - res[0];
return res;
}
int main() {
cin >> n;
g.resize(n);
for(int i = 0; i < n; i++) {
cin >> g[i];
if(g[i] < 1) {
cerr << "Invalid rank " << g[i] << " at index " << i << endl;
exit(0);
}
}
int max_rank = *max_element(g.begin(), g.end());
rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
for(int r = 0; r <= max_rank; r++) {
for(int i = 1; i <= n; i++) {
rank_count[r][i] = rank_count[r][i - 1];
if(g[i - 1] == r)
rank_count[r][i]++;
}
}
for(int i = 0; i <= n; i++)
for(int r = 1; r <= max_rank; r++)
rank_count[r][i] += rank_count[r - 1][i];
int res = find_best(n);
cout << res << endl << "Query count: " << query_count << endl;
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
396 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
308 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
308 KB |
Output is correct |
10 |
Correct |
2 ms |
392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
392 KB |
Output is correct |
6 |
Correct |
2 ms |
392 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
252 KB |
Output is correct |
11 |
Correct |
4 ms |
296 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
8 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
248 KB |
Output is correct |
15 |
Correct |
10 ms |
380 KB |
Output is correct |
16 |
Correct |
40 ms |
248 KB |
Output is correct |
17 |
Correct |
2 ms |
392 KB |
Output is correct |
18 |
Partially correct |
41 ms |
248 KB |
Partially correct - number of queries: 5048 |
19 |
Correct |
2 ms |
248 KB |
Output is correct |
20 |
Correct |
12 ms |
376 KB |
Output is correct |
21 |
Correct |
19 ms |
248 KB |
Output is correct |
22 |
Correct |
6 ms |
248 KB |
Output is correct |
23 |
Correct |
2 ms |
252 KB |
Output is correct |
24 |
Correct |
2 ms |
248 KB |
Output is correct |
25 |
Correct |
24 ms |
304 KB |
Output is correct |
26 |
Correct |
27 ms |
252 KB |
Output is correct |
27 |
Correct |
3 ms |
248 KB |
Output is correct |
28 |
Correct |
46 ms |
248 KB |
Output is correct |
29 |
Correct |
33 ms |
252 KB |
Output is correct |
30 |
Correct |
29 ms |
248 KB |
Output is correct |
31 |
Correct |
2 ms |
312 KB |
Output is correct |
32 |
Correct |
6 ms |
304 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
14 ms |
304 KB |
Output is correct |
35 |
Correct |
3 ms |
248 KB |
Output is correct |
36 |
Correct |
8 ms |
504 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
308 KB |
Output is correct |
39 |
Correct |
23 ms |
248 KB |
Output is correct |
40 |
Correct |
24 ms |
388 KB |
Output is correct |
41 |
Correct |
28 ms |
248 KB |
Output is correct |
42 |
Correct |
31 ms |
392 KB |
Output is correct |
43 |
Correct |
15 ms |
504 KB |
Output is correct |
44 |
Correct |
17 ms |
308 KB |
Output is correct |
45 |
Correct |
15 ms |
248 KB |
Output is correct |
46 |
Correct |
2 ms |
248 KB |
Output is correct |
47 |
Correct |
29 ms |
248 KB |
Output is correct |
48 |
Correct |
35 ms |
296 KB |
Output is correct |
49 |
Correct |
6 ms |
304 KB |
Output is correct |
50 |
Partially correct |
55 ms |
248 KB |
Partially correct - number of queries: 5007 |
51 |
Correct |
24 ms |
248 KB |
Output is correct |
52 |
Correct |
2 ms |
248 KB |
Output is correct |
53 |
Correct |
3 ms |
248 KB |
Output is correct |
54 |
Correct |
13 ms |
388 KB |
Output is correct |
55 |
Correct |
2 ms |
376 KB |
Output is correct |
56 |
Partially correct |
49 ms |
304 KB |
Partially correct - number of queries: 5043 |
57 |
Correct |
20 ms |
392 KB |
Output is correct |
58 |
Correct |
30 ms |
376 KB |
Output is correct |
59 |
Correct |
18 ms |
376 KB |
Output is correct |
60 |
Correct |
27 ms |
248 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
2 ms |
392 KB |
Output is correct |
63 |
Correct |
3 ms |
252 KB |
Output is correct |
64 |
Correct |
3 ms |
248 KB |
Output is correct |
65 |
Correct |
2 ms |
376 KB |
Output is correct |
66 |
Correct |
2 ms |
308 KB |
Output is correct |
67 |
Correct |
2 ms |
312 KB |
Output is correct |
68 |
Correct |
2 ms |
376 KB |
Output is correct |
69 |
Correct |
2 ms |
248 KB |
Output is correct |
70 |
Correct |
2 ms |
376 KB |
Output is correct |
71 |
Correct |
27 ms |
252 KB |
Output is correct |
72 |
Correct |
8 ms |
248 KB |
Output is correct |
73 |
Correct |
49 ms |
248 KB |
Output is correct |
74 |
Correct |
54 ms |
248 KB |
Output is correct |
75 |
Correct |
4 ms |
376 KB |
Output is correct |
76 |
Correct |
36 ms |
248 KB |
Output is correct |
77 |
Partially correct |
74 ms |
248 KB |
Partially correct - number of queries: 5177 |
78 |
Correct |
11 ms |
248 KB |
Output is correct |
79 |
Correct |
15 ms |
388 KB |
Output is correct |
80 |
Partially correct |
49 ms |
244 KB |
Partially correct - number of queries: 5243 |
81 |
Partially correct |
53 ms |
376 KB |
Partially correct - number of queries: 5221 |
82 |
Partially correct |
52 ms |
248 KB |
Partially correct - number of queries: 5125 |
83 |
Correct |
3 ms |
376 KB |
Output is correct |
84 |
Correct |
49 ms |
248 KB |
Output is correct |
85 |
Partially correct |
50 ms |
376 KB |
Partially correct - number of queries: 5180 |
86 |
Correct |
8 ms |
248 KB |
Output is correct |
87 |
Correct |
4 ms |
248 KB |
Output is correct |
88 |
Correct |
7 ms |
376 KB |
Output is correct |
89 |
Correct |
6 ms |
248 KB |
Output is correct |
90 |
Correct |
3 ms |
376 KB |
Output is correct |
91 |
Correct |
5 ms |
248 KB |
Output is correct |
92 |
Correct |
2 ms |
248 KB |
Output is correct |
93 |
Correct |
5 ms |
248 KB |
Output is correct |
94 |
Correct |
5 ms |
376 KB |
Output is correct |
95 |
Correct |
5 ms |
248 KB |
Output is correct |
96 |
Correct |
4 ms |
300 KB |
Output is correct |
97 |
Correct |
3 ms |
248 KB |
Output is correct |