#include <bits/stdc++.h>
#include "koala.h"
using namespace std;
const int MAXN = 105;
int n, w, flg;
int dp[105][105];
int B[MAXN], R[MAXN];
bool f (int ll, int rr, int c) {
vector <int> a, b;
for (int i = n; i >= 1; i--) {
if (ll <= i && i <= rr) {
if (a.empty()) a.push_back(i); else a.push_back(a.back() + i);
} else {
if (b.empty()) b.push_back(i); else b.push_back(b.back() + i);
}
}
vector < pair <int, int> > res;
int mx = -1;
for (int i=0; i<=a.size(); i++) {
for (int j=0; j<=b.size(); j++) {
int cost = i * (c + 1) + j;
int val = 0;
if (i > 0) val += a[i-1];
if (j > 0) val += b[j-1];
if (cost <= w) {
if (val > mx) {
mx = val;
res.clear();
res.push_back(make_pair(i, j));
} else if (val == mx) {
res.push_back(make_pair(i, j));
}
}
}
}
for (auto par : res) {
if (par.first == 0 || par.first == a.size()) return 0;
}
return 1;
}
int calc (int ll, int rr) {
int len = rr - ll + 1;
int mx = w / len;
for (int i = mx; i >= 1; i--) {
if (f(ll, rr, i)) return i;
}
return -1;
}
void precompute () {
for (int i=1; i<=n; i++) {
for (int j=i+1; j<=n; j++) {
dp[i][j] = calc(i, j);
}
}
}
vector <int> rjesi (int lo, int hi, vector <int> v) {
if (lo == hi) return v;
for (int i=0; i<n; i++) {
B[i] = R[i] = 0;
}
for (auto x : v) {
B[x] = dp[lo][hi];
}
playRound(B, R);
vector <int> lef, rig;
for (auto x : v) {
if (R[x] > B[x]) rig.push_back(x); else lef.push_back(x);
}
if (flg == 0) lef = rjesi(lo, lo + lef.size() - 1, lef);
rig = rjesi(lo + lef.size(), hi, rig);
if (flg) return rig;
for (auto x : rig) lef.push_back(x);
return lef;
}
int minValue(int N, int W) {
n = N; w = W;
for (int i=0; i<n; i++) {
B[i] = R[i] = 0;
}
B[0] = 1;
playRound(B, R);
for (int i=0; i<n; i++) {
if (R[i] == 0) return i;
}
}
int maxValue(int N, int W) {
n = N; w = W;
if (flg == 0) precompute();
flg++;
vector <int> sol;
for (int i=0; i<n; i++) sol.push_back(i);
return rjesi(1, n, sol).back();
}
int greaterValue(int N, int W) {
n = N; w = W;
int lo = 1, hi = min(W / 2, 9);
while (lo <= hi) {
int mid = (lo + hi) / 2;
for (int i=0; i<n; i++) {
B[i] = R[i] = 0;
}
B[0] = B[1] = mid;
playRound(B, R);
bool ok0 = R[0] > B[0];
bool ok1 = R[1] > B[1];
if (ok0 == ok1) {
if (ok0 == 1) {
lo = mid + 1;
} else {
hi = mid - 1;
}
} else {
if (ok0) return 0;
return 1;
}
}
}
void allValues(int N, int W, int *P) {
n = N; w = W;
precompute();
vector <int> sol;
for (int i=0; i<n; i++) sol.push_back(i);
sol = rjesi(1, n, sol);
for (int i=0; i<N; i++) {
P[sol[i]] = i + 1;
}
}
Compilation message
koala.cpp: In function 'bool f(int, int, int)':
koala.cpp:23:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<=a.size(); i++) {
~^~~~~~~~~~
koala.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0; j<=b.size(); j++) {
~^~~~~~~~~~
koala.cpp:41:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (par.first == 0 || par.first == a.size()) return 0;
~~~~~~~~~~^~~~~~~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:93:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:127:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
412 KB |
Output is correct |
2 |
Correct |
76 ms |
512 KB |
Output is correct |
3 |
Correct |
75 ms |
376 KB |
Output is correct |
4 |
Correct |
74 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
376 KB |
Output is correct |
2 |
Correct |
69 ms |
812 KB |
Output is correct |
3 |
Correct |
59 ms |
792 KB |
Output is correct |
4 |
Correct |
59 ms |
760 KB |
Output is correct |
5 |
Correct |
60 ms |
760 KB |
Output is correct |
6 |
Correct |
61 ms |
768 KB |
Output is correct |
7 |
Correct |
60 ms |
760 KB |
Output is correct |
8 |
Correct |
60 ms |
764 KB |
Output is correct |
9 |
Correct |
60 ms |
984 KB |
Output is correct |
10 |
Correct |
60 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
376 KB |
Output is correct |
2 |
Correct |
46 ms |
504 KB |
Output is correct |
3 |
Correct |
46 ms |
376 KB |
Output is correct |
4 |
Correct |
46 ms |
376 KB |
Output is correct |
5 |
Correct |
47 ms |
380 KB |
Output is correct |
6 |
Correct |
47 ms |
376 KB |
Output is correct |
7 |
Correct |
46 ms |
376 KB |
Output is correct |
8 |
Correct |
46 ms |
376 KB |
Output is correct |
9 |
Correct |
47 ms |
376 KB |
Output is correct |
10 |
Correct |
46 ms |
408 KB |
Output is correct |
11 |
Correct |
46 ms |
380 KB |
Output is correct |
12 |
Correct |
47 ms |
376 KB |
Output is correct |
13 |
Correct |
46 ms |
376 KB |
Output is correct |
14 |
Correct |
46 ms |
376 KB |
Output is correct |
15 |
Correct |
46 ms |
376 KB |
Output is correct |
16 |
Correct |
46 ms |
376 KB |
Output is correct |
17 |
Correct |
46 ms |
372 KB |
Output is correct |
18 |
Correct |
46 ms |
376 KB |
Output is correct |
19 |
Correct |
46 ms |
376 KB |
Output is correct |
20 |
Correct |
46 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
500 KB |
Output is correct |
2 |
Correct |
64 ms |
380 KB |
Output is correct |
3 |
Correct |
64 ms |
396 KB |
Output is correct |
4 |
Correct |
64 ms |
504 KB |
Output is correct |
5 |
Correct |
64 ms |
376 KB |
Output is correct |
6 |
Correct |
63 ms |
376 KB |
Output is correct |
7 |
Correct |
63 ms |
368 KB |
Output is correct |
8 |
Correct |
63 ms |
376 KB |
Output is correct |
9 |
Correct |
64 ms |
376 KB |
Output is correct |
10 |
Correct |
64 ms |
376 KB |
Output is correct |
11 |
Correct |
63 ms |
376 KB |
Output is correct |
12 |
Correct |
64 ms |
512 KB |
Output is correct |
13 |
Correct |
64 ms |
376 KB |
Output is correct |
14 |
Correct |
63 ms |
376 KB |
Output is correct |
15 |
Correct |
64 ms |
376 KB |
Output is correct |
16 |
Correct |
64 ms |
376 KB |
Output is correct |
17 |
Correct |
64 ms |
376 KB |
Output is correct |
18 |
Correct |
63 ms |
376 KB |
Output is correct |
19 |
Correct |
64 ms |
376 KB |
Output is correct |
20 |
Correct |
64 ms |
376 KB |
Output is correct |
21 |
Correct |
65 ms |
376 KB |
Output is correct |
22 |
Correct |
64 ms |
368 KB |
Output is correct |
23 |
Correct |
63 ms |
376 KB |
Output is correct |
24 |
Correct |
64 ms |
376 KB |
Output is correct |
25 |
Correct |
64 ms |
376 KB |
Output is correct |
26 |
Correct |
64 ms |
384 KB |
Output is correct |
27 |
Correct |
64 ms |
376 KB |
Output is correct |
28 |
Correct |
64 ms |
376 KB |
Output is correct |
29 |
Correct |
64 ms |
376 KB |
Output is correct |
30 |
Correct |
64 ms |
376 KB |
Output is correct |
31 |
Correct |
64 ms |
376 KB |
Output is correct |
32 |
Correct |
64 ms |
504 KB |
Output is correct |
33 |
Correct |
64 ms |
376 KB |
Output is correct |
34 |
Correct |
64 ms |
376 KB |
Output is correct |
35 |
Correct |
64 ms |
636 KB |
Output is correct |
36 |
Correct |
65 ms |
404 KB |
Output is correct |
37 |
Correct |
64 ms |
376 KB |
Output is correct |
38 |
Correct |
65 ms |
376 KB |
Output is correct |
39 |
Correct |
63 ms |
376 KB |
Output is correct |
40 |
Correct |
64 ms |
376 KB |
Output is correct |