#include "koala.h"
#include <bits/stdc++.h>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvt = vt< vt<int> >;
int a[100], b[100];
int minValue(int n, int w) {
fill(a, a + n, 0);
a[0] = 1;
playRound(a, b);
for (int i = 1; i < n; i++) if (b[i] == 0) return i;
return 0;
}
int maxValue (int n, int w) {
vt<int> p(n);
iota(all(p), 0ll);
while (sz(p) != 1) {
fill(a, a + n, 0);
int x = w / sz(p);
for (int i: p) a[i] = x;
playRound(a, b);
p.clear();
for (int i = 0; i < n; i++) if (b[i] == x + 1) p.pb(i);
}
return p[0];
}
int greaterValue (int n, int w) {
fill(a, a + n, 0);
int l = 1, r = 13, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
fill(a, a + n, 0);
a[0] = a[1] = mid;
playRound(a, b);
if (b[0] != b[1]) return (b[0] < b[1]);
if (b[0] > mid && b[1] > mid) ans = mid, l = mid + 1;
else r = mid - 1;
}
a[0] = a[1] = ans;
playRound(a, b);
return (b[0] < b[1]);
}
bool comp (int i, int j, int n, int w) {
fill(a, a + n, 0);
a[i] = a[j] = w / 2;
playRound(a, b);
return (b[j] > w / 2);
}
vt<int> merge_sort (vt<int> &v, int n, int w) {
if (sz(v) == 1) return v;
vt<int> l, r;
for (int i = 0; i < sz(v); i++) {
if (i < sz(v) / 2) l.pb(v[i]);
else r.pb(v[i]);
}
l = merge_sort(l, n, w);
r = merge_sort(r, n, w);
v.clear();
int i = 0, j = 0;
while (i < sz(l) && j < sz(r)) v.pb((comp(l[i], r[j], n, w) ? l[i++] : r[j++]));
while (i < sz(l)) v.pb(l[i++]);
while (j < sz(r)) v.pb(r[j++]);
return v;
}
void solve (vt<int> &v, int l, int r, int n, int w, int *p) {
if (l == r) {
p[v[0]] = l;
return;
}
int x = min((int)sqrt(l * 2), w / (r - l + 1));
fill(a, a + n, 0);
for (int i: v) a[i] = x;
playRound(a, b);
vt<int> L, R;
for (int i: v) {
if (b[i] == x + 1) R.pb(i);
else L.pb(i);
}
solve(L, l, l + sz(L) - 1, n, w, p);
solve(R, r - sz(R) + 1, r, n, w, p);
}
void allValues (int n, int w, int *p) {
vt<int> v(n);
iota(all(v), 0);
if (w == n * 2) {
v = merge_sort(v, n, w);
for (int i = 0; i < n; i++) p[v[i]] = i + 1;
return;
}
solve(v, 1, n, n, w, p);
playRound(a, b);
playRound(a, b);
playRound(a, b);
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
208 KB |
Output is correct |
2 |
Correct |
11 ms |
320 KB |
Output is correct |
3 |
Correct |
11 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
328 KB |
Output is correct |
2 |
Correct |
44 ms |
336 KB |
Output is correct |
3 |
Correct |
38 ms |
324 KB |
Output is correct |
4 |
Correct |
37 ms |
336 KB |
Output is correct |
5 |
Correct |
40 ms |
336 KB |
Output is correct |
6 |
Correct |
37 ms |
332 KB |
Output is correct |
7 |
Correct |
43 ms |
332 KB |
Output is correct |
8 |
Correct |
50 ms |
336 KB |
Output is correct |
9 |
Correct |
39 ms |
336 KB |
Output is correct |
10 |
Correct |
37 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
324 KB |
Output is correct |
2 |
Correct |
28 ms |
324 KB |
Output is correct |
3 |
Correct |
34 ms |
316 KB |
Output is correct |
4 |
Correct |
28 ms |
320 KB |
Output is correct |
5 |
Correct |
28 ms |
320 KB |
Output is correct |
6 |
Correct |
31 ms |
320 KB |
Output is correct |
7 |
Correct |
28 ms |
320 KB |
Output is correct |
8 |
Correct |
27 ms |
320 KB |
Output is correct |
9 |
Correct |
28 ms |
316 KB |
Output is correct |
10 |
Correct |
31 ms |
320 KB |
Output is correct |
11 |
Correct |
27 ms |
324 KB |
Output is correct |
12 |
Correct |
18 ms |
320 KB |
Output is correct |
13 |
Correct |
29 ms |
316 KB |
Output is correct |
14 |
Correct |
26 ms |
328 KB |
Output is correct |
15 |
Correct |
26 ms |
320 KB |
Output is correct |
16 |
Correct |
23 ms |
316 KB |
Output is correct |
17 |
Correct |
23 ms |
320 KB |
Output is correct |
18 |
Correct |
24 ms |
208 KB |
Output is correct |
19 |
Correct |
24 ms |
316 KB |
Output is correct |
20 |
Correct |
25 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
448 KB |
Output is partially correct |
3 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
320 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
6 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
7 |
Partially correct |
3 ms |
328 KB |
Output is partially correct |
8 |
Partially correct |
3 ms |
320 KB |
Output is partially correct |
9 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
10 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
11 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
12 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
13 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
14 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
15 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
17 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
18 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
19 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
20 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
21 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
22 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
23 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
24 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
25 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
26 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
27 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
28 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
29 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
30 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
31 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
32 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
33 |
Partially correct |
3 ms |
320 KB |
Output is partially correct |
34 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
35 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
36 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
37 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
38 |
Partially correct |
4 ms |
208 KB |
Output is partially correct |
39 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |
40 |
Partially correct |
3 ms |
208 KB |
Output is partially correct |