#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "koala.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
////
//static int N, W;
//static int P[105];
//
//static int maxQueries = 3200;
//static int numQueries;
//
//static void runGame(int F);
//static void grader();
//
//void playRound(int *B, int *R) {
// int i, j;
//
// int S = 0;
// for (i=0;i<N;++i) {
// if ( !(B[i] >= 0 && B[i] <= W) ) {
// printf("Invalid query.\n");
// exit(0);
// }
// S += B[i];
// }
// if (S > W) {
// printf("Invalid query.\n");
// exit(0);
// }
//
// numQueries++;
// if (numQueries > maxQueries) {
// printf("Too many queries.\n");
// exit(0);
// }
//
// int cache[2][205];
// int num[2][205];
// char taken[105][205];
//
// for (i=0;i<205;++i) {
// cache[1][i] = 0;
// num[1][i] = 0;
// }
//
// for (i=0;i<N;++i) {
// int v = B[i]+1;
// int ii = i&1;
// int o = ii^1;
// for (j=0;j<=W;++j) {
// cache[ii][j] = cache[o][j];
// num[ii][j] = num[o][j];
// taken[i][j] = 0;
// }
// for (j=W;j>=v;--j) {
// int h = cache[o][j-v] + P[i];
// int hn = num[o][j-v] + 1;
// if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
// cache[ii][j] = h;
// num[ii][j] = hn;
// taken[i][j] = 1;
// } else {
// taken[i][j] = 0;
// }
// }
// }
//
// int cur = W;
// for (i=N-1;i>=0;--i) {
// R[i] = taken[i][cur] ? (B[i] + 1) : 0;
// cur -= R[i];
// }
//}
int minValue(int N, int W) {
int B[105];
int R[105];
memset(B, 0, sizeof(B));
memset(R, 0, sizeof(R));
B[0] = 1;
playRound(B, R);
for (int i = 0; i < N; ++i)
if (R[i] == 0) return i;
return 0;
}
int maxValue(int N, int W) {
vector <int> cands;
for (int i = 0; i < N; ++i) cands.push_back(i);
while (cands.size() > 1) {
int B[105];
int R[105];
memset(B, 0, sizeof(B));
memset(R, 0, sizeof(R));
for (auto x: cands) B[x] = W / cands.size();
playRound(B, R);
vector <int> ncands;
int maxi = *max_element(R, R + N);
for (auto x: cands)
if (R[x] == maxi) ncands.push_back(x);
swap(cands, ncands);
}
return cands[0];
}
int greaterValue(int N, int W) {
int lo = 0, hi = W / 6;
while (lo <= hi) {
int mid = lo + hi >> 1;
int B[105];
int R[105];
memset(B, 0, sizeof(B));
memset(R, 0, sizeof(R));
B[0] = B[1] = mid;
playRound(B, R);
int ok0 = (R[0] > mid);
int ok1 = (R[1] > mid);
if (ok0 ^ ok1) return (ok0 ? 0 : 1);
if (!ok0) hi = mid - 1;
else lo = mid + 1;
}
}
void allValues(int N, int W, int *P) {
if (W != 2 * N) {
int p[N];
memset(p, 0, sizeof(p));
for (int i = 0; i < N; ++i) p[i] = i;
sort(p, p + N, [&](int u, int v) {
int lo = 0, hi = W / 6;
while (lo <= hi) {
int mid = lo + hi >> 1;
int B[105];
int R[105];
memset(B, 0, sizeof(B));
memset(R, 0, sizeof(R));
B[u] = B[v] = mid;
playRound(B, R);
int ok0 = (R[u] > mid);
int ok1 = (R[v] > mid);
if (ok0 ^ ok1) return (ok0 ? 0 : 1);
if (!ok0) hi = mid - 1;
else lo = mid + 1;
}
});
for (int i = 0; i < N; ++i) P[p[i]] = i + 1;
} else {
int p[N];
memset(p, 0, sizeof(p));
for (int i = 0; i < N; ++i) p[i] = i;
auto cmp = [&](int u, int v) {
int B[105];
int R[105];
memset(B, 0, sizeof(B));
memset(R, 0, sizeof(R));
B[u] = B[v] = N;
playRound(B, R);
return (R[u] < R[v]);
};
function <void(int, int)> sort = [&](int L, int R) {
if (L >= R) return;
int mid = L + R >> 1;
sort(L, mid);
sort(mid + 1, R);
vector <int> cur;
int i = L, j = mid + 1;
while (i <= mid && j <= R) {
if (cmp(p[i], p[j])) cur.push_back(p[i++]);
else cur.push_back(p[j++]);
}
// assert(i > mid || j > R);
while (i <= mid) cur.push_back(p[i++]);
while (j <= R) cur.push_back(p[j++]);
// assert(cur.size() == R - L + 1);
for (int i = 0; i < cur.size(); ++i) p[i + L] = cur[i];
};
sort(0, N - 1);
for (int i = 0; i < N; ++i) P[p[i]] = i + 1;
}
}
//
//int main() {
// grader();
// return 0;
//}
//
//
//static void runGame(int F) {
// int i;
//
// scanf("%d %d",&N,&W);
// for (i=0;i<N;++i) {
// scanf("%d",&P[i]);
// }
//
// numQueries = 0;
// if (F == 1) {
// printf("%d\n", minValue(N, W));
// } else if (F == 2) {
// printf("%d\n", maxValue(N, W));
// } else if (F == 3) {
// printf("%d\n", greaterValue(N, W));
// } else if (F == 4) {
// int userP[105];
// allValues(N, W, userP);
// for (i=0;i<N;i++) {
// printf("%d ",userP[i]);
// }
// printf("\n");
// }
// printf("Made %d calls to playRound.\n", numQueries);
//}
//
//static void grader() {
// int i;
//
// int F, G;
// scanf("%d %d",&F,&G);
//
// for (i=0;i<G;i++) {
// runGame(F);
// }
//}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:117:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
117 | int mid = lo + hi >> 1;
| ~~~^~~~
koala.cpp: In lambda function:
koala.cpp:140:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
140 | int mid = lo + hi >> 1;
| ~~~^~~~
koala.cpp: In lambda function:
koala.cpp:170:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
170 | int mid = L + R >> 1;
| ~~^~~
koala.cpp:183:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
183 | for (int i = 0; i < cur.size(); ++i) p[i + L] = cur[i];
| ~~^~~~~~~~~~~~
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:130:1: warning: control reaches end of non-void function [-Wreturn-type]
130 | }
| ^
koala.cpp: In lambda function:
koala.cpp:153:9: warning: control reaches end of non-void function [-Wreturn-type]
153 | });
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
5 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
4 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
320 KB |
Output is correct |
2 |
Correct |
11 ms |
320 KB |
Output is correct |
3 |
Correct |
12 ms |
316 KB |
Output is correct |
4 |
Correct |
13 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
320 KB |
Output is correct |
2 |
Correct |
46 ms |
328 KB |
Output is correct |
3 |
Correct |
44 ms |
340 KB |
Output is correct |
4 |
Correct |
40 ms |
328 KB |
Output is correct |
5 |
Correct |
41 ms |
336 KB |
Output is correct |
6 |
Correct |
42 ms |
332 KB |
Output is correct |
7 |
Correct |
59 ms |
336 KB |
Output is correct |
8 |
Correct |
44 ms |
324 KB |
Output is correct |
9 |
Correct |
57 ms |
324 KB |
Output is correct |
10 |
Correct |
40 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
208 KB |
Output is correct |
2 |
Correct |
32 ms |
208 KB |
Output is correct |
3 |
Correct |
40 ms |
300 KB |
Output is correct |
4 |
Correct |
29 ms |
208 KB |
Output is correct |
5 |
Correct |
30 ms |
308 KB |
Output is correct |
6 |
Correct |
33 ms |
296 KB |
Output is correct |
7 |
Correct |
27 ms |
312 KB |
Output is correct |
8 |
Correct |
28 ms |
208 KB |
Output is correct |
9 |
Correct |
30 ms |
292 KB |
Output is correct |
10 |
Correct |
28 ms |
208 KB |
Output is correct |
11 |
Correct |
30 ms |
208 KB |
Output is correct |
12 |
Correct |
16 ms |
312 KB |
Output is correct |
13 |
Correct |
29 ms |
208 KB |
Output is correct |
14 |
Correct |
26 ms |
208 KB |
Output is correct |
15 |
Correct |
26 ms |
304 KB |
Output is correct |
16 |
Correct |
27 ms |
328 KB |
Output is correct |
17 |
Correct |
25 ms |
316 KB |
Output is correct |
18 |
Correct |
26 ms |
296 KB |
Output is correct |
19 |
Correct |
25 ms |
208 KB |
Output is correct |
20 |
Correct |
25 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
26 ms |
292 KB |
Output is partially correct |
2 |
Partially correct |
27 ms |
208 KB |
Output is partially correct |
3 |
Partially correct |
27 ms |
292 KB |
Output is partially correct |
4 |
Partially correct |
32 ms |
292 KB |
Output is partially correct |
5 |
Partially correct |
27 ms |
312 KB |
Output is partially correct |
6 |
Partially correct |
26 ms |
208 KB |
Output is partially correct |
7 |
Partially correct |
30 ms |
308 KB |
Output is partially correct |
8 |
Partially correct |
27 ms |
208 KB |
Output is partially correct |
9 |
Partially correct |
28 ms |
284 KB |
Output is partially correct |
10 |
Partially correct |
23 ms |
208 KB |
Output is partially correct |
11 |
Partially correct |
25 ms |
208 KB |
Output is partially correct |
12 |
Partially correct |
17 ms |
208 KB |
Output is partially correct |
13 |
Partially correct |
24 ms |
208 KB |
Output is partially correct |
14 |
Partially correct |
26 ms |
304 KB |
Output is partially correct |
15 |
Partially correct |
27 ms |
312 KB |
Output is partially correct |
16 |
Partially correct |
36 ms |
208 KB |
Output is partially correct |
17 |
Partially correct |
37 ms |
312 KB |
Output is partially correct |
18 |
Partially correct |
29 ms |
308 KB |
Output is partially correct |
19 |
Partially correct |
25 ms |
316 KB |
Output is partially correct |
20 |
Partially correct |
25 ms |
296 KB |
Output is partially correct |
21 |
Partially correct |
23 ms |
208 KB |
Output is partially correct |
22 |
Partially correct |
27 ms |
208 KB |
Output is partially correct |
23 |
Partially correct |
21 ms |
208 KB |
Output is partially correct |
24 |
Partially correct |
29 ms |
292 KB |
Output is partially correct |
25 |
Partially correct |
30 ms |
208 KB |
Output is partially correct |
26 |
Partially correct |
28 ms |
208 KB |
Output is partially correct |
27 |
Partially correct |
32 ms |
208 KB |
Output is partially correct |
28 |
Partially correct |
28 ms |
208 KB |
Output is partially correct |
29 |
Partially correct |
28 ms |
296 KB |
Output is partially correct |
30 |
Partially correct |
27 ms |
208 KB |
Output is partially correct |
31 |
Partially correct |
26 ms |
208 KB |
Output is partially correct |
32 |
Partially correct |
28 ms |
316 KB |
Output is partially correct |
33 |
Partially correct |
25 ms |
208 KB |
Output is partially correct |
34 |
Partially correct |
21 ms |
316 KB |
Output is partially correct |
35 |
Partially correct |
25 ms |
208 KB |
Output is partially correct |
36 |
Partially correct |
26 ms |
324 KB |
Output is partially correct |
37 |
Partially correct |
26 ms |
296 KB |
Output is partially correct |
38 |
Partially correct |
25 ms |
208 KB |
Output is partially correct |
39 |
Partially correct |
26 ms |
312 KB |
Output is partially correct |
40 |
Partially correct |
34 ms |
208 KB |
Output is partially correct |