#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
//#define TEST
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
const int len = 2e5+5;
ii arr[len];
int pos, n, sum;
/*vector<int> ask(int i) {
fprintf(fout, "A %d\n", i);
fflush(fout);
vector<int> result(2);
if (fscanf(fin, "%d %d", &result[0], &result[1]) != 2) {
cerr << "tester error" << endl;
cerr << "could not read query response" << endl;
exit(0);
}
if (result[0] < 0) {
exit(0);
}
return result;
}*/
#ifdef TEST
vector<int> ask(int i){
printf("ask %d\n", i), fflush(stdout);
int a, b;
scanf("%d %d", &a, &b);
vector<int> temp;
temp.pb(a), temp.pb(b);
return temp;
}
#endif
ii val(int i){
if (arr[i] != mp(-1, -1))
return arr[i];
vector<int> temp = ask(i);
return arr[i] = mp(temp[0], temp[1]);
}
int bs(){
int l = pos, r = n-1, ans;
while (l <= r){
int mid = (l+r)/2;
if (val(mid) == val(pos)){
ans = mid;
l = mid+1;
}
else
r = mid-1;
}
return ans;
}
int find_best(int N){
n = N, sum = 0, pos = 0;
for (int i = 0; i < n; i++)
arr[i] = mp(-1, -1);
for (int i = 0; i < min(500, n); i++)
sum = max(sum, val(i).fi + val(i).se);
while (pos < n){
if (val(pos).fi+val(pos).se != sum){
if (val(pos) == mp(0, 0))
return pos;
pos++;
}
else{
pos = bs() + 1;
}
}
return 0;
}
#ifdef TEST
int main(int argc, char **argv) {
int n;
scanf("%d", &n);
printf("%d\n", find_best(n));
return 0;
}
#endif
Compilation message
prize.cpp: In function 'int bs()':
prize.cpp:64:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
return ans;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
15 ms |
1920 KB |
Output is correct |
3 |
Correct |
8 ms |
1920 KB |
Output is correct |
4 |
Correct |
7 ms |
1924 KB |
Output is correct |
5 |
Correct |
10 ms |
1976 KB |
Output is correct |
6 |
Correct |
7 ms |
1976 KB |
Output is correct |
7 |
Correct |
9 ms |
2092 KB |
Output is correct |
8 |
Correct |
13 ms |
2092 KB |
Output is correct |
9 |
Correct |
12 ms |
2092 KB |
Output is correct |
10 |
Correct |
7 ms |
2144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2144 KB |
Output is correct |
2 |
Correct |
10 ms |
2144 KB |
Output is correct |
3 |
Correct |
7 ms |
2144 KB |
Output is correct |
4 |
Correct |
12 ms |
2144 KB |
Output is correct |
5 |
Correct |
10 ms |
2144 KB |
Output is correct |
6 |
Correct |
12 ms |
2144 KB |
Output is correct |
7 |
Correct |
13 ms |
2144 KB |
Output is correct |
8 |
Correct |
12 ms |
2144 KB |
Output is correct |
9 |
Correct |
9 ms |
2144 KB |
Output is correct |
10 |
Correct |
9 ms |
2144 KB |
Output is correct |
11 |
Correct |
12 ms |
2144 KB |
Output is correct |
12 |
Correct |
12 ms |
2144 KB |
Output is correct |
13 |
Correct |
21 ms |
2144 KB |
Output is correct |
14 |
Correct |
12 ms |
2144 KB |
Output is correct |
15 |
Correct |
20 ms |
2144 KB |
Output is correct |
16 |
Partially correct |
97 ms |
2144 KB |
Partially correct - number of queries: 7218 |
17 |
Correct |
11 ms |
2144 KB |
Output is correct |
18 |
Partially correct |
97 ms |
2144 KB |
Partially correct - number of queries: 8378 |
19 |
Correct |
7 ms |
2144 KB |
Output is correct |
20 |
Correct |
23 ms |
2144 KB |
Output is correct |
21 |
Correct |
52 ms |
2144 KB |
Output is correct |
22 |
Correct |
17 ms |
2144 KB |
Output is correct |
23 |
Correct |
10 ms |
2144 KB |
Output is correct |
24 |
Correct |
11 ms |
2144 KB |
Output is correct |
25 |
Correct |
69 ms |
2144 KB |
Output is correct |
26 |
Correct |
50 ms |
2144 KB |
Output is correct |
27 |
Correct |
11 ms |
2144 KB |
Output is correct |
28 |
Partially correct |
64 ms |
2144 KB |
Partially correct - number of queries: 7903 |
29 |
Partially correct |
86 ms |
2144 KB |
Partially correct - number of queries: 6143 |
30 |
Partially correct |
67 ms |
2144 KB |
Partially correct - number of queries: 8307 |
31 |
Correct |
11 ms |
2144 KB |
Output is correct |
32 |
Correct |
8 ms |
2144 KB |
Output is correct |
33 |
Correct |
4 ms |
2144 KB |
Output is correct |
34 |
Correct |
35 ms |
2144 KB |
Output is correct |
35 |
Correct |
14 ms |
2144 KB |
Output is correct |
36 |
Correct |
30 ms |
2144 KB |
Output is correct |
37 |
Correct |
10 ms |
2144 KB |
Output is correct |
38 |
Correct |
12 ms |
2144 KB |
Output is correct |
39 |
Correct |
29 ms |
2144 KB |
Output is correct |
40 |
Partially correct |
56 ms |
2144 KB |
Partially correct - number of queries: 7178 |
41 |
Partially correct |
90 ms |
2144 KB |
Partially correct - number of queries: 5238 |
42 |
Partially correct |
54 ms |
2144 KB |
Partially correct - number of queries: 5238 |
43 |
Correct |
46 ms |
2144 KB |
Output is correct |
44 |
Correct |
36 ms |
2144 KB |
Output is correct |
45 |
Correct |
17 ms |
2144 KB |
Output is correct |
46 |
Correct |
11 ms |
2144 KB |
Output is correct |
47 |
Correct |
50 ms |
2144 KB |
Output is correct |
48 |
Partially correct |
84 ms |
2144 KB |
Partially correct - number of queries: 6334 |
49 |
Correct |
18 ms |
2144 KB |
Output is correct |
50 |
Partially correct |
84 ms |
2144 KB |
Partially correct - number of queries: 8379 |
51 |
Correct |
28 ms |
2144 KB |
Output is correct |
52 |
Correct |
6 ms |
2144 KB |
Output is correct |
53 |
Correct |
12 ms |
2144 KB |
Output is correct |
54 |
Correct |
26 ms |
2144 KB |
Output is correct |
55 |
Correct |
11 ms |
2144 KB |
Output is correct |
56 |
Partially correct |
65 ms |
2144 KB |
Partially correct - number of queries: 8374 |
57 |
Partially correct |
32 ms |
2144 KB |
Partially correct - number of queries: 6238 |
58 |
Partially correct |
62 ms |
2144 KB |
Partially correct - number of queries: 6320 |
59 |
Partially correct |
72 ms |
2144 KB |
Partially correct - number of queries: 5235 |
60 |
Correct |
60 ms |
2144 KB |
Output is correct |
61 |
Correct |
14 ms |
2144 KB |
Output is correct |
62 |
Correct |
10 ms |
2144 KB |
Output is correct |
63 |
Correct |
10 ms |
2144 KB |
Output is correct |
64 |
Correct |
7 ms |
2144 KB |
Output is correct |
65 |
Correct |
8 ms |
2144 KB |
Output is correct |
66 |
Correct |
11 ms |
2144 KB |
Output is correct |
67 |
Correct |
11 ms |
2144 KB |
Output is correct |
68 |
Correct |
12 ms |
2144 KB |
Output is correct |
69 |
Correct |
17 ms |
2144 KB |
Output is correct |
70 |
Correct |
12 ms |
2144 KB |
Output is correct |
71 |
Partially correct |
112 ms |
2144 KB |
Partially correct - number of queries: 8270 |
72 |
Correct |
9 ms |
2144 KB |
Output is correct |
73 |
Partially correct |
93 ms |
2144 KB |
Partially correct - number of queries: 8159 |
74 |
Partially correct |
92 ms |
2144 KB |
Partially correct - number of queries: 8219 |
75 |
Correct |
12 ms |
2144 KB |
Output is correct |
76 |
Partially correct |
68 ms |
2144 KB |
Partially correct - number of queries: 7113 |
77 |
Partially correct |
37 ms |
2144 KB |
Partially correct - number of queries: 7051 |
78 |
Correct |
17 ms |
2144 KB |
Output is correct |
79 |
Correct |
55 ms |
2144 KB |
Output is correct |
80 |
Partially correct |
96 ms |
2144 KB |
Partially correct - number of queries: 8409 |
81 |
Partially correct |
82 ms |
2144 KB |
Partially correct - number of queries: 8420 |
82 |
Partially correct |
76 ms |
2144 KB |
Partially correct - number of queries: 8353 |
83 |
Correct |
13 ms |
2144 KB |
Output is correct |
84 |
Partially correct |
68 ms |
2144 KB |
Partially correct - number of queries: 6970 |
85 |
Partially correct |
92 ms |
2144 KB |
Partially correct - number of queries: 8433 |
86 |
Correct |
10 ms |
2144 KB |
Output is correct |
87 |
Correct |
9 ms |
2144 KB |
Output is correct |
88 |
Correct |
11 ms |
2144 KB |
Output is correct |
89 |
Correct |
13 ms |
2144 KB |
Output is correct |
90 |
Correct |
8 ms |
2144 KB |
Output is correct |
91 |
Correct |
12 ms |
2144 KB |
Output is correct |
92 |
Correct |
10 ms |
2144 KB |
Output is correct |
93 |
Correct |
11 ms |
2144 KB |
Output is correct |
94 |
Correct |
16 ms |
2144 KB |
Output is correct |
95 |
Correct |
15 ms |
2144 KB |
Output is correct |
96 |
Correct |
16 ms |
2144 KB |
Output is correct |
97 |
Correct |
9 ms |
2144 KB |
Output is correct |