// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
#include "koala.h"
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 200005
int minValue(int n, int w) {
int b[n], r[n];
REP (i, 0, n) {
b[i] = 0;
}
b[0] = 1;
playRound(b, r);
REP (i, 0, n) {
if (r[i] == 0) {
return i;
}
}
assert(0);
}
int maxValue(int n, int w) {
int b[n], r[n];
REP (i, 0, n) {
b[i] = 1;
}
playRound(b, r);
vi big;
REP (i, 0, n) {
if (r[i] > 1) {
big.pb(i);
}
}
while (big.size() > 1) {
int x = w / big.size();
REP (i, 0, n) {
b[i] = 0;
}
for (int i : big) {
b[i] = x;
}
playRound(b, r);
big.clear();
REP (i, 0, n) {
if (r[i] > 1) {
big.pb(i);
}
}
}
assert(big.size() == 1);
return big[0];
}
int greaterValue(int n, int w) {
int lo = 1, hi = min(w / 2, 9), mid;
while (lo <= hi) {
mid = lo + hi >> 1;
int b[n], r[n];
REP (i, 0, n) {
b[i] = 0;
}
b[0] = b[1] = mid;
playRound(b, r);
bool is0 = r[0] > mid, is1 = r[1] > mid;
if (is0 != is1) {
if (is0) {
return 0;
} else {
return 1;
}
}
if (is0) {
lo = mid + 1;
} else {
hi = mid - 1;
}
}
assert(0);
return 0;
}
int res[105];
template <class T>
void my_sort(int *arr, int l, int r, T &&f) {
int n = r - l;
if (n <= 1) return;
int m = l + r + 1 >> 1;
my_sort(arr, l, m, f);
my_sort(arr, m, r, f);
int a = l, b = m, c = l;
while (a < m && b < r) {
if (f(arr[a], arr[b])) {
res[c++] = arr[a++];
} else {
res[c++] = arr[b++];
}
}
while (a < m) {
res[c++] = arr[a++];
}
while (b < r) {
res[c++] = arr[b++];
}
REP (i, l, r) {
arr[i] = res[i];
}
}
void allValues(int n, int w, int *p) {
if (w == 2 * n) {
int id[n];
iota(id, id + n, 0);
my_sort(id, 0, n, [&] (int l, int r) {
int b[n], c[n];
REP (i, 0, n) {
b[i] = 0;
}
b[l] = b[r] = n;
playRound(b, c);
return c[l] <= n;
});
REP (i, 0, n) {
p[id[i]] = i + 1;
}
} else {
auto solve = [&] (int s, int e, vi vec, auto &&solve) {
if (vec.size() == 1) {
p[vec[0]] = s;
return;
}
int x = min((int) sqrt(s), w / (int) vec.size());
cerr << s << ' ' << e << ' ' << x << '\n';
int b[n], r[n];
REP (i, 0, n) {
b[i] = 0;
}
for (auto i : vec) {
b[i] = x;
}
playRound(b, r);
vi big, small;
for (auto i : vec) {
if (r[i] > x) {
big.pb(i);
} else {
small.pb(i);
}
}
assert(!big.empty());
assert(!small.empty());
int k = s + small.size() - 1;
solve(s, k, small, solve); solve(k + 1, e, big, solve);
};
vi vec(n, 0);
iota(ALL(vec), 0);
solve(1, n, vec, solve);
}
}
Compilation message
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:88:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
88 | mid = lo + hi >> 1;
| ~~~^~~~
koala.cpp: In instantiation of 'void my_sort(int*, int, int, T&&) [with T = allValues(int, int, int*)::<lambda(int, int)>]':
koala.cpp:152:18: required from here
koala.cpp:118:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
118 | int m = l + r + 1 >> 1;
| ~~~~~~^~~
koala.cpp: In instantiation of 'void my_sort(int*, int, int, T&&) [with T = allValues(int, int, int*)::<lambda(int, int)>&]':
koala.cpp:119:12: required from 'void my_sort(int*, int, int, T&&) [with T = allValues(int, int, int*)::<lambda(int, int)>]'
koala.cpp:152:18: required from here
koala.cpp:118:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
4 ms |
208 KB |
Output is correct |
3 |
Correct |
4 ms |
208 KB |
Output is correct |
4 |
Correct |
4 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
208 KB |
Output is correct |
2 |
Correct |
12 ms |
208 KB |
Output is correct |
3 |
Correct |
13 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
332 KB |
Output is correct |
2 |
Correct |
56 ms |
324 KB |
Output is correct |
3 |
Correct |
52 ms |
328 KB |
Output is correct |
4 |
Correct |
53 ms |
328 KB |
Output is correct |
5 |
Correct |
46 ms |
336 KB |
Output is correct |
6 |
Correct |
49 ms |
328 KB |
Output is correct |
7 |
Correct |
48 ms |
316 KB |
Output is correct |
8 |
Correct |
48 ms |
316 KB |
Output is correct |
9 |
Correct |
47 ms |
328 KB |
Output is correct |
10 |
Correct |
48 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
312 KB |
Output is correct |
2 |
Correct |
30 ms |
312 KB |
Output is correct |
3 |
Correct |
28 ms |
296 KB |
Output is correct |
4 |
Correct |
29 ms |
296 KB |
Output is correct |
5 |
Correct |
27 ms |
316 KB |
Output is correct |
6 |
Correct |
28 ms |
208 KB |
Output is correct |
7 |
Correct |
27 ms |
208 KB |
Output is correct |
8 |
Correct |
27 ms |
296 KB |
Output is correct |
9 |
Correct |
27 ms |
208 KB |
Output is correct |
10 |
Correct |
26 ms |
292 KB |
Output is correct |
11 |
Correct |
28 ms |
328 KB |
Output is correct |
12 |
Correct |
16 ms |
316 KB |
Output is correct |
13 |
Correct |
27 ms |
208 KB |
Output is correct |
14 |
Correct |
25 ms |
292 KB |
Output is correct |
15 |
Correct |
25 ms |
208 KB |
Output is correct |
16 |
Correct |
25 ms |
208 KB |
Output is correct |
17 |
Correct |
23 ms |
208 KB |
Output is correct |
18 |
Correct |
26 ms |
208 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 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
4 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
3 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 |
208 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 |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 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 |
208 KB |
Output is correct |
25 |
Correct |
3 ms |
208 KB |
Output is correct |
26 |
Correct |
3 ms |
208 KB |
Output is correct |
27 |
Correct |
3 ms |
208 KB |
Output is correct |
28 |
Correct |
3 ms |
328 KB |
Output is correct |
29 |
Correct |
3 ms |
320 KB |
Output is correct |
30 |
Correct |
3 ms |
208 KB |
Output is correct |
31 |
Correct |
3 ms |
336 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 |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
208 KB |
Output is correct |
36 |
Correct |
4 ms |
320 KB |
Output is correct |
37 |
Correct |
5 ms |
208 KB |
Output is correct |
38 |
Correct |
3 ms |
324 KB |
Output is correct |
39 |
Correct |
3 ms |
332 KB |
Output is correct |
40 |
Correct |
3 ms |
208 KB |
Output is correct |