#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
bool pres[MAXN];
int n, w;
int t = 0;
vector<int> query(vector<int> &inp) {
int *a = new int[n];
int *b = new int[n];
for (int i = 0; i < n; i++) a[i] = inp[i];
playRound(a, b);
vector<int> out;
for (int i = 0; i < n; i++) {
if (b[i] > inp[i]) out.push_back(i);
}
delete[] a;
delete[] b;
return out;
}
vector<int> complement(vector<int> inp) {
fill(pres, pres+n, 0);
for (int v: inp) pres[v] = 1;
vector<int> out;
for (int i = 0; i < n; i++)
if (!pres[i]) out.push_back(i);
return out;
}
vector<int> inter(vector<int> a, vector<int> &b) {
fill(pres, pres+n, 0);
for (int v: a) pres[v] = 1;
vector<int> out;
for (int v: b)
if (pres[v]) out.push_back(v);
return out;
}
int minValue(int N, int W) {
n = N; w = W;
vector<int> vals(n, 0);
vals[0] = 1;
return complement(query(vals))[0];
}
int maxValue(int N, int W) {
n = N; w = W;
vector<int> cur(n, 0);
iota(cur.begin(), cur.end(), 0);
while (cur.size() > 1) {
int put = n/cur.size();
vector<int> qry(n, 0);
for (int v: cur) qry[v] = put;
cur = inter(query(qry), cur);
}
return cur[0];
}
int greaterValue(int N, int W) {
n = N; w = W;
vector<int> put({1, 2, 5, 10});
int mn = -1, mx = 4;
vector<int> two({0, 1});
while (mx > mn+1) {
int cur = (mn+mx)/2;
vector<int> qry(n, 0);
qry[0] = qry[1] = put[cur];
vector<int> vals = inter(query(qry), two);
if (vals.size() == 2) mn = cur;
else if (vals.empty()) mx = cur;
else {
return vals[0];
}
}
assert(false);
return 0;
}
bool smaller(int &a, int &b) {
t++;
// assert(t <= 100);
vector<int> qry(n, 0);
qry[a] = qry[b] = n;
vector<int> two({a, b});
return inter(query(qry), two)[0] == b;
}
void make_sort(vector<int> &a, int l, int r) {
if (r <= l) return;
vector<int> ex;
int mid = (l+r)/2;
make_sort(a, l, mid);
make_sort(a, mid+1, r);
for (int i = l; i <= r; i++) ex.push_back(a[i]);
int p1 = 0, p2 = mid+1-l;
int j = 0;
while (p1 <= mid-l || p2 <= r-l) {
if (p1 > mid-l) {
a[l+(j++)] = ex[p2];
p2++;
}
else if (p2 > r-l) {
a[l+(j++)] = ex[p1];
p1++;
}
else if (smaller(ex[p1], ex[p2])) {
a[l+(j++)] = ex[p1];
p1++;
}
else {
a[l+(j++)] = ex[p2];
p2++;
}
}
}
vector<int> answer;
int sum(int a) {
return a*(a+1)/2;
}
void solve(int l, int r, vector<int> &rev) { // ignore everything above r essentially
if (l > r) return;
if (l == r) {
answer[rev[0]] = l+1;
return;
}
int put = 0;
if (l > 0) {
int b = 0;
do {
put++;
b += r-l+1;
} while (put < n/(r-l+1) && sum(min(l, b))-sum(max(0, b-(put+1))) < l+1);
}
else put = 1;
vector<int> qry(n, 0);
for (int v: rev) qry[v] = put;
vector<int> up = inter(query(qry), rev);
vector<int> down = inter(complement(up), rev);
solve(r-up.size()+1, r, up);
solve(l, r-up.size(), down);
}
void allValues(int N, int W, int *P) {
n = N; w = W;
if (W == 2*N) {
t = 0;
vector<int> ans(n);
iota(ans.begin(), ans.end(), 0);
make_sort(ans, 0, n-1);
// sort(ans.begin(), ans.end(), comp);
for (int i = 0; i < n; i++) P[ans[i]] = i+1;
} else {
answer = vector<int>(n);
vector<int> curv(n);
iota(curv.begin(), curv.end(), 0);
solve(0, n-1, curv);
for (int i = 0; i < n; i++) P[i] = answer[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 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 |
10 ms |
316 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
12 ms |
316 KB |
Output is correct |
4 |
Correct |
10 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
452 KB |
Output is correct |
2 |
Correct |
61 ms |
328 KB |
Output is correct |
3 |
Correct |
61 ms |
328 KB |
Output is correct |
4 |
Correct |
60 ms |
328 KB |
Output is correct |
5 |
Correct |
61 ms |
328 KB |
Output is correct |
6 |
Correct |
61 ms |
332 KB |
Output is correct |
7 |
Correct |
63 ms |
332 KB |
Output is correct |
8 |
Correct |
62 ms |
332 KB |
Output is correct |
9 |
Correct |
61 ms |
320 KB |
Output is correct |
10 |
Correct |
59 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
208 KB |
Output is correct |
2 |
Correct |
26 ms |
304 KB |
Output is correct |
3 |
Correct |
25 ms |
208 KB |
Output is correct |
4 |
Correct |
25 ms |
208 KB |
Output is correct |
5 |
Correct |
24 ms |
208 KB |
Output is correct |
6 |
Correct |
27 ms |
312 KB |
Output is correct |
7 |
Correct |
25 ms |
208 KB |
Output is correct |
8 |
Correct |
24 ms |
208 KB |
Output is correct |
9 |
Correct |
24 ms |
316 KB |
Output is correct |
10 |
Correct |
24 ms |
316 KB |
Output is correct |
11 |
Correct |
25 ms |
312 KB |
Output is correct |
12 |
Correct |
14 ms |
316 KB |
Output is correct |
13 |
Correct |
25 ms |
296 KB |
Output is correct |
14 |
Correct |
23 ms |
328 KB |
Output is correct |
15 |
Correct |
22 ms |
316 KB |
Output is correct |
16 |
Correct |
22 ms |
208 KB |
Output is correct |
17 |
Correct |
22 ms |
320 KB |
Output is correct |
18 |
Correct |
23 ms |
208 KB |
Output is correct |
19 |
Correct |
22 ms |
208 KB |
Output is correct |
20 |
Correct |
23 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
4 ms |
208 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
336 KB |
Output is correct |
17 |
Correct |
3 ms |
208 KB |
Output is correct |
18 |
Correct |
3 ms |
208 KB |
Output is correct |
19 |
Correct |
3 ms |
336 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
268 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
208 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
328 KB |
Output is correct |
28 |
Correct |
3 ms |
208 KB |
Output is correct |
29 |
Correct |
3 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
3 ms |
208 KB |
Output is correct |
32 |
Correct |
3 ms |
208 KB |
Output is correct |
33 |
Correct |
3 ms |
208 KB |
Output is correct |
34 |
Correct |
3 ms |
208 KB |
Output is correct |
35 |
Correct |
3 ms |
208 KB |
Output is correct |
36 |
Correct |
3 ms |
208 KB |
Output is correct |
37 |
Correct |
3 ms |
336 KB |
Output is correct |
38 |
Correct |
3 ms |
208 KB |
Output is correct |
39 |
Correct |
3 ms |
328 KB |
Output is correct |
40 |
Correct |
3 ms |
328 KB |
Output is correct |