#include "koala.h"
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
mt19937 rng(192929);
const int MaxN = 2e5 + 3;
int b[MaxN], r[MaxN];
int minValue(int N, int W) {
int x = rng() % N;
FOR(i, N) b[i] = 0;
b[x] = 1;
playRound(b, r);
int pos_x = 0;
while(r[pos_x]) ++pos_x;
if(r[x] == 2) return pos_x;
int y = rng() % N ;
b[x] = 0;
b[y] = 1;
playRound(b, r);
int pos_y;
while(r[pos_y]) ++pos_y;
if(r[y] == 2) return pos_y;
if(pos_x == pos_y) return pos_x;
return (rng() & 1) ? pos_x : pos_y;
}
int potential[MaxN];
int maxValue(int N, int W) {
FOR(i, N) potential[i] = 1;
while(true)
{
int cnt = 0;
FOR(i, N)
cnt += potential[i];
if(cnt == 1)
FOR(i, N) if(potential[i]) return i;
if(cnt == 0) assert(0);
FOR(i, N)
if(potential[i])
b[i] = W / cnt;
else b[i] = 0;
playRound(b, r);
FOR(i, N ) if(r[i] && potential[i]) potential[i] = 1;
else potential[i] = 0;
}
return 0;
}
int greaterValue(int N, int W) {
int lb = 1, rb = min(W / 2, 9);
FOR(i, N) b[i] = 0;
while(lb <= rb)
{
int mid = lb + rb >> 1;
b[0] = b[1] = mid;
//FOR(i, N) cout << b[i] << " "; cout << endl;
playRound(b, r);
int c1 = r[0] > b[0], c2 = r[1] > b[1];
if(c1 ^ c2) return c1 < c2;
if(c1) lb = mid + 1;
else rb = mid - 1;
}
return 0;
}
void dnc(vector<int> &cur, int lb, int rb, int *P, int N, int W, bool ok)
{
if(lb > rb) return;
if(lb == rb) P[cur[0]] = lb;
else
{
FOR(i, N) b[i] = 0;
for(int x : cur) b[x] = ok ? min(int(sqrt(lb * 2)), W / (rb - lb + 1)) : W / (rb - lb + 1);
playRound(b, r);
vector<int> L;
vector<int> R;
for(int x : cur) if(r[x] > b[x]) R.push_back(x);
else L.push_back(x);
dnc(L, lb, lb + (L.size()) - 1, P, N, W, ok);
dnc(R, rb - (R.size()) + 1, rb, P, N, W, ok);
}
}
void allValues(int N, int W, int *P) {
vector<int> cur;
FOR(i, N) cur.push_back(i);
dnc(cur, 1, N , P, N, W, W == N);
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:76:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int mid = lb + rb >> 1;
| ~~~^~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:39:18: warning: 'pos_y' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | while(r[pos_y]) ++pos_y;
| ~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2392 KB |
Output is correct |
2 |
Correct |
4 ms |
2392 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
4 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
2392 KB |
Output is correct |
2 |
Correct |
11 ms |
2520 KB |
Output is correct |
3 |
Correct |
11 ms |
2392 KB |
Output is correct |
4 |
Correct |
10 ms |
2516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
2536 KB |
Output is correct |
2 |
Correct |
48 ms |
2548 KB |
Output is correct |
3 |
Correct |
41 ms |
2552 KB |
Output is correct |
4 |
Correct |
41 ms |
2536 KB |
Output is correct |
5 |
Correct |
42 ms |
2548 KB |
Output is correct |
6 |
Correct |
42 ms |
2552 KB |
Output is correct |
7 |
Correct |
47 ms |
2392 KB |
Output is correct |
8 |
Correct |
43 ms |
2532 KB |
Output is correct |
9 |
Correct |
42 ms |
2552 KB |
Output is correct |
10 |
Correct |
50 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2516 KB |
Output is correct |
3 |
Correct |
6 ms |
2392 KB |
Output is correct |
4 |
Correct |
7 ms |
2392 KB |
Output is correct |
5 |
Correct |
5 ms |
2392 KB |
Output is correct |
6 |
Correct |
6 ms |
2392 KB |
Output is correct |
7 |
Correct |
5 ms |
2392 KB |
Output is correct |
8 |
Correct |
5 ms |
2392 KB |
Output is correct |
9 |
Correct |
6 ms |
2392 KB |
Output is correct |
10 |
Correct |
5 ms |
2392 KB |
Output is correct |
11 |
Correct |
5 ms |
2392 KB |
Output is correct |
12 |
Correct |
5 ms |
2392 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
5 ms |
2392 KB |
Output is correct |
15 |
Correct |
5 ms |
2644 KB |
Output is correct |
16 |
Correct |
5 ms |
2392 KB |
Output is correct |
17 |
Correct |
5 ms |
2392 KB |
Output is correct |
18 |
Correct |
5 ms |
2524 KB |
Output is correct |
19 |
Correct |
5 ms |
2516 KB |
Output is correct |
20 |
Correct |
6 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2512 KB |
Output is correct |
3 |
Correct |
3 ms |
2392 KB |
Output is correct |
4 |
Correct |
3 ms |
2392 KB |
Output is correct |
5 |
Correct |
4 ms |
2392 KB |
Output is correct |
6 |
Correct |
3 ms |
2392 KB |
Output is correct |
7 |
Correct |
3 ms |
2392 KB |
Output is correct |
8 |
Correct |
3 ms |
2392 KB |
Output is correct |
9 |
Correct |
3 ms |
2392 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
3 ms |
2392 KB |
Output is correct |
12 |
Correct |
3 ms |
2392 KB |
Output is correct |
13 |
Correct |
5 ms |
2392 KB |
Output is correct |
14 |
Correct |
3 ms |
2392 KB |
Output is correct |
15 |
Correct |
4 ms |
2392 KB |
Output is correct |
16 |
Correct |
3 ms |
2392 KB |
Output is correct |
17 |
Correct |
3 ms |
2392 KB |
Output is correct |
18 |
Correct |
4 ms |
2392 KB |
Output is correct |
19 |
Correct |
3 ms |
2392 KB |
Output is correct |
20 |
Correct |
3 ms |
2496 KB |
Output is correct |
21 |
Correct |
3 ms |
2392 KB |
Output is correct |
22 |
Correct |
3 ms |
2392 KB |
Output is correct |
23 |
Correct |
3 ms |
2392 KB |
Output is correct |
24 |
Correct |
3 ms |
2392 KB |
Output is correct |
25 |
Correct |
3 ms |
2516 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
27 |
Correct |
3 ms |
2392 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
3 ms |
2392 KB |
Output is correct |
30 |
Correct |
3 ms |
2392 KB |
Output is correct |
31 |
Correct |
3 ms |
2392 KB |
Output is correct |
32 |
Correct |
4 ms |
2392 KB |
Output is correct |
33 |
Correct |
3 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2392 KB |
Output is correct |
35 |
Correct |
3 ms |
2516 KB |
Output is correct |
36 |
Correct |
3 ms |
2392 KB |
Output is correct |
37 |
Correct |
3 ms |
2492 KB |
Output is correct |
38 |
Correct |
3 ms |
2516 KB |
Output is correct |
39 |
Correct |
3 ms |
2392 KB |
Output is correct |
40 |
Correct |
3 ms |
2392 KB |
Output is correct |