#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
// #define LOCAL
#ifdef LOCAL
void playRound(int *B, int *R);
#else
#include "koala.h"
#endif
int B[100], R[100];
void clr() {
F0R(i,100) B[i] = 0;
}
int minValue(int N, int W) {
clr();
B[0] = 1;
playRound(B,R);
F0R(i,N) if (R[i] <= B[i]) return i;
return -1;
}
void prin() {
F0R(i,100) cout << B[i] << " ";
cout << "\n";
F0R(i,100) cout << R[i] << " ";
cout << "\n";
}
void upd(vi& v) {
vi V; for (int i: v) if (R[i] > B[i]) V.pb(i);
v = V;
}
int maxValue(int N, int W) {
vi cand; F0R(i,N) cand.pb(i);
while (sz(cand) > 1) {
clr(); for (int i: cand) B[i] = 100/sz(cand);
playRound(B,R);
upd(cand);
}
return cand[0];
}
int greaterValue(int N, int W) {
int lo = 1, hi = 9;
while (1) {
int mid = (lo+hi)/2;
clr(); B[0] = B[1] = mid;
playRound(B,R);
if (R[0] > B[0]) {
if (R[1] > B[1]) {
lo = mid+1;
} else {
return 0;
}
} else {
if (R[1] > B[1]) {
return 1;
} else {
hi = mid-1;
}
}
}
}
int cdiv(int x, int y) { return (x+y-1)/y; }
void divi(int N, int W, int *P, int mx, vi cand) {
if (sz(cand) == 1) {
P[cand[0]] = mx;
return;
}
int wei = W/sz(cand);
if (W == N) {
wei = min(wei,8);
if (mx <= 8) wei = 2;
if (mx == 2) wei = 1;
if (mx == 16 && sz(cand) == 2) wei = 5;
if ((mx == 18 || mx == 19) && sz(cand) <= 3) wei = 6;
if (mx == 21 && sz(cand) == 2) wei = 6;
if (mx == 25 && sz(cand) == 2) wei = 7;
}
clr();
for (int i: cand) B[i] = wei;
playRound(B,R);
vi a,b;
for (int i: cand) {
if (R[i] <= B[i]) a.pb(i);
else b.pb(i);
}
/*if (sz(a) == 0 || sz(b) == 0) {
cout << wei << " " << sz(a) << " " << sz(b) << " " << mx-sz(cand)+1 << " " << mx << "\n";
return;
}*/
divi(N,W,P,mx-sz(b),a);
divi(N,W,P,mx,b);
}
void allValues(int N, int W, int *P) {
F0R(i,N) P[i] = 0;
vi cand; F0R(i,N) cand.pb(i);
if (W == 2*N) {
divi(N,W,P,N,cand);
} else {
vi cand; F0R(i,N) cand.pb(i);
divi(N,W,P,N,cand);
}
}
#ifdef LOCAL
static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
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] + P[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];
}
}
static void runGame(int F) {
int i;
scanf("%d %d",&N,&W);
for (i=0;i<N;++i) {
scanf("%d",&P[i]);
}
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
printf("%d\n", greaterValue(N, W));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
456 KB |
Output is correct |
3 |
Correct |
8 ms |
456 KB |
Output is correct |
4 |
Correct |
7 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
476 KB |
Output is correct |
2 |
Correct |
19 ms |
568 KB |
Output is correct |
3 |
Correct |
18 ms |
672 KB |
Output is correct |
4 |
Correct |
17 ms |
672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
820 KB |
Output is correct |
2 |
Correct |
83 ms |
820 KB |
Output is correct |
3 |
Correct |
67 ms |
820 KB |
Output is correct |
4 |
Correct |
70 ms |
820 KB |
Output is correct |
5 |
Correct |
79 ms |
824 KB |
Output is correct |
6 |
Correct |
77 ms |
824 KB |
Output is correct |
7 |
Correct |
80 ms |
824 KB |
Output is correct |
8 |
Correct |
67 ms |
824 KB |
Output is correct |
9 |
Correct |
65 ms |
824 KB |
Output is correct |
10 |
Correct |
64 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
824 KB |
Output is correct |
2 |
Correct |
11 ms |
824 KB |
Output is correct |
3 |
Correct |
10 ms |
824 KB |
Output is correct |
4 |
Correct |
10 ms |
824 KB |
Output is correct |
5 |
Correct |
8 ms |
824 KB |
Output is correct |
6 |
Correct |
11 ms |
824 KB |
Output is correct |
7 |
Correct |
8 ms |
824 KB |
Output is correct |
8 |
Correct |
11 ms |
824 KB |
Output is correct |
9 |
Correct |
10 ms |
824 KB |
Output is correct |
10 |
Correct |
9 ms |
824 KB |
Output is correct |
11 |
Correct |
13 ms |
824 KB |
Output is correct |
12 |
Correct |
12 ms |
824 KB |
Output is correct |
13 |
Correct |
9 ms |
824 KB |
Output is correct |
14 |
Correct |
11 ms |
824 KB |
Output is correct |
15 |
Correct |
9 ms |
824 KB |
Output is correct |
16 |
Correct |
12 ms |
824 KB |
Output is correct |
17 |
Correct |
10 ms |
824 KB |
Output is correct |
18 |
Correct |
9 ms |
824 KB |
Output is correct |
19 |
Correct |
12 ms |
824 KB |
Output is correct |
20 |
Correct |
9 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
824 KB |
Output is correct |
2 |
Correct |
6 ms |
824 KB |
Output is correct |
3 |
Correct |
6 ms |
824 KB |
Output is correct |
4 |
Correct |
6 ms |
824 KB |
Output is correct |
5 |
Correct |
6 ms |
824 KB |
Output is correct |
6 |
Correct |
7 ms |
824 KB |
Output is correct |
7 |
Correct |
8 ms |
824 KB |
Output is correct |
8 |
Correct |
6 ms |
824 KB |
Output is correct |
9 |
Correct |
9 ms |
824 KB |
Output is correct |
10 |
Correct |
6 ms |
824 KB |
Output is correct |
11 |
Correct |
8 ms |
824 KB |
Output is correct |
12 |
Correct |
8 ms |
824 KB |
Output is correct |
13 |
Correct |
6 ms |
824 KB |
Output is correct |
14 |
Correct |
7 ms |
824 KB |
Output is correct |
15 |
Correct |
7 ms |
824 KB |
Output is correct |
16 |
Correct |
6 ms |
824 KB |
Output is correct |
17 |
Correct |
5 ms |
824 KB |
Output is correct |
18 |
Correct |
6 ms |
824 KB |
Output is correct |
19 |
Correct |
5 ms |
824 KB |
Output is correct |
20 |
Correct |
8 ms |
824 KB |
Output is correct |
21 |
Correct |
7 ms |
824 KB |
Output is correct |
22 |
Correct |
8 ms |
824 KB |
Output is correct |
23 |
Correct |
6 ms |
824 KB |
Output is correct |
24 |
Correct |
6 ms |
828 KB |
Output is correct |
25 |
Correct |
7 ms |
828 KB |
Output is correct |
26 |
Correct |
7 ms |
828 KB |
Output is correct |
27 |
Correct |
7 ms |
828 KB |
Output is correct |
28 |
Correct |
6 ms |
828 KB |
Output is correct |
29 |
Correct |
6 ms |
828 KB |
Output is correct |
30 |
Correct |
6 ms |
828 KB |
Output is correct |
31 |
Correct |
7 ms |
828 KB |
Output is correct |
32 |
Correct |
6 ms |
828 KB |
Output is correct |
33 |
Correct |
7 ms |
828 KB |
Output is correct |
34 |
Correct |
9 ms |
828 KB |
Output is correct |
35 |
Correct |
8 ms |
828 KB |
Output is correct |
36 |
Correct |
8 ms |
828 KB |
Output is correct |
37 |
Correct |
6 ms |
828 KB |
Output is correct |
38 |
Correct |
6 ms |
828 KB |
Output is correct |
39 |
Correct |
6 ms |
828 KB |
Output is correct |
40 |
Correct |
6 ms |
828 KB |
Output is correct |