This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) {
cerr << 1;
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) {
cerr << 2;
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) {
cerr << 3;
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 check (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> &a, int n, int w) {
if (sz(a) == 1) return a;
vt<int> l, r;
for (int i = 0; i < sz(a); i++) {
if (i < sz(a) / 2) l.pb(a[i]);
else r.pb(a[i]);
}
l = merge_sort(l, n, w);
r = merge_sort(r, n, w);
a.clear();
int i = 0, j = 0;
while (i < sz(l) && j < sz(r)) a.pb((check(l[i], r[j], n, w) ? l[i++] : r[j++]));
while (i < sz(l)) a.pb(l[i++]);
while (j < sz(r)) a.pb(r[j++]);
return a;
}
bool cmp (int i, int j) {
int l = 1, r = 13, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
memset(a, 0, sizeof(a));
a[i] = a[j] = mid;
playRound(a, b);
if (b[i] != b[j]) return (b[i] < b[j]);
if (b[i] > mid && b[j] > mid) ans = mid, l = mid + 1;
else r = mid - 1;
}
a[i] = a[j] = ans;
playRound(a, b);
return (b[i] < b[j]);
}
void f(vt<int> s, int l, int r, int w, int *p) {
if (l == r) {
p[s[0]] = l;
return;
}
int v = 0;
for (int x = 1; x <= w / (r - l + 1); x++) {
int i = r, j = 1;
int cnt = r - l + 1;
while (i >= l) {
int sum = 0;
while (j < l && sum <= i && cnt <= x) {
sum += j;
cnt++;
j++;
}
if (cnt > x) {
cnt -= x + 1;
i--;
continue;
}
break;
}
if (i >= l && i < r) {
v = x;
break;
}
}
for (int i = 0; i < w; i++) a[i] = 0;
for (int i: s) a[i] = v;
playRound(a, b);
vt<int> tl, tr;
for (int i: s) {
if (b[i] > v) tr.pb(i);
else tl.pb(i);
}
f(tl, l, l + sz(tl) - 1, w, p);
f(tr, l + sz(tl), r, w, p);
}
void allValues (int n, int w, int *p) {
if (w == n * 2) {
vt<int> v(n);
iota(all(v), 0ll);
v = merge_sort(v, n, w);
for (int i = 0; i < n; i++) p[v[i]] = i + 1;
return;
}
vt<int> s;
for (int i = 0; i < n; i++) s.pb(i);
f(s, 1, n, w, p);
}
Compilation message (stderr)
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int mid = l + r >> 1;
| ~~^~~
koala.cpp: In function 'bool cmp(int, int)':
koala.cpp:89:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
89 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |