//Never stop trying
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#ifndef LOCAL
#include "koala.h"
#endif
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int P[100];
int N,W;
#ifdef LOCAL
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) {
here();
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];
}
}
#endif
int B[100],R[100];
int minValue(int NN, int WW) {
N=NN; W=WW;
/*
Place only one item in any element:
-If there is an empty element: it is the MinValue
-Else the element in which I placed the item is the MinValue
*/
FOR(i,0,N) B[i]=0;
B[0]=1;
playRound(B,R);
FOR(i,0,N) if(R[i]==0) return i;
return 0;
}
int maxValue(int NN, int WW) {
N=NN; W=WW;
/*
.for every 10 elements place 10 items
.from those 10 elements, we won't choose more than 1 element (proved)
.if it was chosen, it is bigger than (10*11/2)==55
.for all the elements chosen (<=10), put 10 on them
.the chosen is the max
*/
vi chosen;
for(int i=0; i<100; i+=10){
FOR(j,0,N) B[j]=0;
FOR(j,i,i+10) B[j]=10;
playRound(B,R);
//dbgv(B); dbgv(R);
int x=-1;
FOR(j,i,i+10){
//cout << R[j] << ' ';
if(R[j]>10){
//cout << P[j] << endl;
chosen.pb(j);
//assert(x==-1);
x=0;
}
}
//cout << endl;
}
FOR(i,0,N) B[i]=0;
for(auto x: chosen) B[x]=10;
playRound(B,R);
for(auto x: chosen) if(R[x]>10) return x;
return 0;
}
int greaterValue(int NN, int WW) {
N=NN; W=WW;
/*
BS([1,13]) on the number of elements put on both of those
.if she choose both, make it bigger
.if she choose no one, make it smaller
.if she choose only one, that one is the biggest
!!Choose = put on it more than I put
*/
int l=0,r=14;
while(l<=r){
int m=(l+r)/2;
FOR(i,0,N) B[i]=0;
B[0]=m; B[1]=m;
playRound(B,R);
dbg(m);
dbgv(R);
if(R[0]>m && R[1]>m) l=m+1;
else if(R[0]<=m && R[1]<=m) r=m-1;
else if(R[0]>m) return 0;
else return 1;
}
assert(0);
return 0;
}
vi adj[101];
bool vis[101];
vi top;
void dfs(int u){
vis[u]=true;
for(auto v: adj[u]) if(!vis[v]) dfs(v);
top.pb(u);
}
void allValues(int NN, int WW, int *PP) {
N=NN; W=WW;
vi v[14];
FOR(i,0,N){
int l=0,r=13;
int ans;
while(l<=r){
int m=(l+r)/2;
FOR(idx,0,N) B[idx]=0;
B[i]=m;
playRound(B,R);
if(R[i]>m){
ans=m;
l=m+1;
}
else r=m-1;
}
v[ans].pb(i);
}
//dbgv(v[12]);
FOR(i,0,14) FOR(j,i+1,14){
for(auto u: v[i]) for(auto k: v[j]) adj[u].pb(k);
}
FOR(i,1,14){
vi vec=v[i];
FOR(j,0,sz(vec)) FOR(k,j+1,sz(vec)){
int u=vec[j],vv=vec[k];
FOR(idx,0,N) vis[idx]=0;
dfs(u); if(vis[vv]) continue;
FOR(idx,0,N) vis[idx]=0;
dfs(vv); if(vis[u]) continue;
FOR(idx,0,N) B[idx]=0;
B[u]=i; B[vv]=i;
playRound(B,R);
bool a=(R[u]>i),b=(R[vv]>i);
if(a&&b) dbgs(u,vv);
if(b){
adj[u].pb(vv);
}
else{
adj[vv].pb(u);
}
}
}
top.clear();
FOR(i,0,N) vis[i]=0;
FOR(i,0,N) if(!vis[i]) dfs(i);
reverse(all(top));
//dbgv(top);
FOR(i,0,N) PP[top[i]]=i+1;
}
#ifdef LOCAL
int main() {
boost; IO();
FOR(i,0,100) P[i]=i+1;
//P[0]=20; P[1]=10; P[9]=1; P[19]=2;
//dbgv(P);
allValues(100,100,P);
//dbgv(P);
return 0;
}
#endif
/* Careful!!!
.Array bounds
.Infinite loops
.Uninitialized variables / empty containers
.Multisets are shit
Some insights:
.Binary search
.Graph representation
.Write brute force code
.Change your approach
*/
Compilation message
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:173:7: warning: variable 'x' set but not used [-Wunused-but-set-variable]
173 | int x=-1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
364 KB |
Output is correct |
4 |
Correct |
6 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
364 KB |
Output is correct |
2 |
Correct |
68 ms |
364 KB |
Output is correct |
3 |
Correct |
59 ms |
364 KB |
Output is correct |
4 |
Correct |
62 ms |
428 KB |
Output is correct |
5 |
Correct |
62 ms |
364 KB |
Output is correct |
6 |
Correct |
62 ms |
364 KB |
Output is correct |
7 |
Correct |
60 ms |
548 KB |
Output is correct |
8 |
Correct |
61 ms |
364 KB |
Output is correct |
9 |
Correct |
61 ms |
364 KB |
Output is correct |
10 |
Correct |
62 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
35 ms |
612 KB |
Output is partially correct |
2 |
Partially correct |
25 ms |
620 KB |
Output is partially correct |
3 |
Partially correct |
26 ms |
748 KB |
Output is partially correct |
4 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
5 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
6 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
7 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
8 |
Partially correct |
27 ms |
612 KB |
Output is partially correct |
9 |
Partially correct |
28 ms |
656 KB |
Output is partially correct |
10 |
Partially correct |
27 ms |
748 KB |
Output is partially correct |
11 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
12 |
Partially correct |
33 ms |
620 KB |
Output is partially correct |
13 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
14 |
Partially correct |
26 ms |
612 KB |
Output is partially correct |
15 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
16 |
Partially correct |
28 ms |
740 KB |
Output is partially correct |
17 |
Partially correct |
27 ms |
612 KB |
Output is partially correct |
18 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
19 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
20 |
Partially correct |
32 ms |
612 KB |
Output is partially correct |
21 |
Partially correct |
27 ms |
668 KB |
Output is partially correct |
22 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
23 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
24 |
Partially correct |
27 ms |
612 KB |
Output is partially correct |
25 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
26 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
27 |
Partially correct |
28 ms |
612 KB |
Output is partially correct |
28 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
29 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
30 |
Partially correct |
27 ms |
612 KB |
Output is partially correct |
31 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
32 |
Partially correct |
26 ms |
620 KB |
Output is partially correct |
33 |
Partially correct |
28 ms |
748 KB |
Output is partially correct |
34 |
Partially correct |
28 ms |
612 KB |
Output is partially correct |
35 |
Partially correct |
26 ms |
612 KB |
Output is partially correct |
36 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |
37 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
38 |
Partially correct |
28 ms |
620 KB |
Output is partially correct |
39 |
Partially correct |
28 ms |
652 KB |
Output is partially correct |
40 |
Partially correct |
27 ms |
620 KB |
Output is partially correct |