// M
#include<bits/stdc++.h>
#include "koala.h"
using namespace std;
const int N = 109;
int B[N], R[N];
int minValue(int n, int W)
{
for (int i = 0; i < n; i ++)
B[i] = 1;
playRound(B, R);
int id = -1;
for (int i = 0; i < n; i ++)
if (R[i] > 1)
id = i;
assert(id != -1);
memset(B, 0, sizeof(B));
B[id] = 1;
playRound(B, R);
for (int i = 0; i < n; i ++)
if (!R[i])
return i;
}
int maxValue(int n, int W)
{
vector < int > Cnds;
for (int i = 0; i < n; i ++)
Cnds.push_back(i);
while (Cnds.size() > 1)
{
memset(B, 0, sizeof(B));
for (int a : Cnds)
B[a] = W / (int)Cnds.size();
playRound(B, R);
vector < int > TbC;
for (int a : Cnds)
if (R[a] > B[a])
TbC.push_back(a);
Cnds.swap(TbC);
TbC.clear();
}
assert(Cnds.size());
return Cnds[0];
}
int greaterValue(int n, int W)
{
int le = 0, ri = min(11, W / 2), md;
while (ri - le > 1)
{
md = (le + ri) >> 1;
memset(B, 0, sizeof(B));
B[0] = md; B[1] = md;
playRound(B, R);
int w0 = R[0] > md, w1 = R[1] > md;
if (w0 && !w1)
return 0;
if (w1 && !w0)
return 1;
if (w0 && w1)
le = md;
else
ri = md;
}
}
inline bool TestRound(int l, int r, int n, int W, int Cw)
{
if (Cw * (r - l + 1) > W)
return 0;
memset(B, 0, sizeof(B));
for (int i = 0; i < n; i ++)
B[i] = 0;
for (int i = l; i <= r; i ++)
B[i - 1] = Cw;
int ORGP[210];
for (int i = 0; i < n; i ++)
ORGP[i] = i + 1;
int i, j;
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<n;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + ORGP[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=n-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
int Pkd = 0;
for (int i = l; i <= r; i ++)
if (R[i - 1] > B[i - 1])
Pkd ++;
if (Pkd == 0 || Pkd == r - l + 1)
return 0;
return 1;
}
void Solve(int l, int r, vector < int > A, int n, int W, int * P)
{
if (r < l)
return ;
if (l == r)
return void(P[A[0]] = l);
int w = W / n;
int Cw = W;
Cw /= (r - l + 1);
while (Cw && !TestRound(l, r, n, W, Cw))
Cw --;
assert(Cw);
memset(B, 0, sizeof(B));
for (int i : A)
B[i] = Cw;
playRound(B, R);
vector < int > Le, Ri;
for (int i : A)
{
if (R[i] > B[i])
Ri.push_back(i);
else
Le.push_back(i);
}
Solve(l, l + (int)Le.size() - 1, Le, n, W, P);
Solve(l + (int)Le.size(), r, Ri, n, W, P);
return ;
}
void allValues(int n, int W, int * P)
{
vector < int > A;
for (int i = 0; i < n; i ++)
A.push_back(i);
Solve(1, n, A, n, W, P);
}
Compilation message
koala.cpp: In function 'void Solve(int, int, std::vector<int>, int, int, int*)':
koala.cpp:139:13: warning: unused variable 'w' [-Wunused-variable]
int w = W / n;
^
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
384 KB |
Output is correct |
4 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
384 KB |
Output is correct |
2 |
Correct |
18 ms |
512 KB |
Output is correct |
3 |
Correct |
20 ms |
384 KB |
Output is correct |
4 |
Correct |
18 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
384 KB |
Output is correct |
2 |
Correct |
86 ms |
384 KB |
Output is correct |
3 |
Correct |
75 ms |
384 KB |
Output is correct |
4 |
Correct |
86 ms |
396 KB |
Output is correct |
5 |
Correct |
73 ms |
384 KB |
Output is correct |
6 |
Correct |
73 ms |
384 KB |
Output is correct |
7 |
Correct |
74 ms |
384 KB |
Output is correct |
8 |
Correct |
74 ms |
384 KB |
Output is correct |
9 |
Correct |
79 ms |
504 KB |
Output is correct |
10 |
Correct |
73 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
384 KB |
Output is correct |
2 |
Correct |
17 ms |
512 KB |
Output is correct |
3 |
Correct |
17 ms |
384 KB |
Output is correct |
4 |
Correct |
17 ms |
384 KB |
Output is correct |
5 |
Correct |
16 ms |
384 KB |
Output is correct |
6 |
Correct |
16 ms |
384 KB |
Output is correct |
7 |
Correct |
16 ms |
384 KB |
Output is correct |
8 |
Correct |
17 ms |
384 KB |
Output is correct |
9 |
Correct |
16 ms |
384 KB |
Output is correct |
10 |
Correct |
16 ms |
384 KB |
Output is correct |
11 |
Correct |
16 ms |
384 KB |
Output is correct |
12 |
Correct |
16 ms |
384 KB |
Output is correct |
13 |
Correct |
16 ms |
384 KB |
Output is correct |
14 |
Correct |
16 ms |
384 KB |
Output is correct |
15 |
Correct |
16 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
384 KB |
Output is correct |
17 |
Correct |
18 ms |
384 KB |
Output is correct |
18 |
Correct |
16 ms |
384 KB |
Output is correct |
19 |
Correct |
18 ms |
384 KB |
Output is correct |
20 |
Correct |
16 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
384 KB |
Output is correct |
2 |
Correct |
59 ms |
384 KB |
Output is correct |
3 |
Correct |
63 ms |
384 KB |
Output is correct |
4 |
Correct |
64 ms |
384 KB |
Output is correct |
5 |
Correct |
60 ms |
504 KB |
Output is correct |
6 |
Correct |
58 ms |
384 KB |
Output is correct |
7 |
Correct |
58 ms |
384 KB |
Output is correct |
8 |
Correct |
59 ms |
384 KB |
Output is correct |
9 |
Correct |
58 ms |
384 KB |
Output is correct |
10 |
Correct |
59 ms |
384 KB |
Output is correct |
11 |
Correct |
59 ms |
384 KB |
Output is correct |
12 |
Correct |
60 ms |
384 KB |
Output is correct |
13 |
Correct |
60 ms |
384 KB |
Output is correct |
14 |
Correct |
60 ms |
384 KB |
Output is correct |
15 |
Correct |
58 ms |
384 KB |
Output is correct |
16 |
Correct |
59 ms |
384 KB |
Output is correct |
17 |
Correct |
58 ms |
384 KB |
Output is correct |
18 |
Correct |
58 ms |
384 KB |
Output is correct |
19 |
Correct |
58 ms |
384 KB |
Output is correct |
20 |
Correct |
58 ms |
384 KB |
Output is correct |
21 |
Correct |
58 ms |
384 KB |
Output is correct |
22 |
Correct |
58 ms |
384 KB |
Output is correct |
23 |
Correct |
59 ms |
384 KB |
Output is correct |
24 |
Correct |
59 ms |
384 KB |
Output is correct |
25 |
Correct |
60 ms |
504 KB |
Output is correct |
26 |
Correct |
58 ms |
384 KB |
Output is correct |
27 |
Correct |
59 ms |
384 KB |
Output is correct |
28 |
Correct |
59 ms |
384 KB |
Output is correct |
29 |
Correct |
58 ms |
384 KB |
Output is correct |
30 |
Correct |
59 ms |
384 KB |
Output is correct |
31 |
Correct |
60 ms |
384 KB |
Output is correct |
32 |
Correct |
58 ms |
288 KB |
Output is correct |
33 |
Correct |
58 ms |
384 KB |
Output is correct |
34 |
Correct |
58 ms |
384 KB |
Output is correct |
35 |
Correct |
60 ms |
384 KB |
Output is correct |
36 |
Correct |
58 ms |
384 KB |
Output is correct |
37 |
Correct |
59 ms |
384 KB |
Output is correct |
38 |
Correct |
59 ms |
384 KB |
Output is correct |
39 |
Correct |
68 ms |
384 KB |
Output is correct |
40 |
Correct |
59 ms |
384 KB |
Output is correct |