Submission #1054366

# Submission time Handle Problem Language Result Execution time Memory
1054366 2024-08-12T09:09:59 Z ㅇ(#11107) Koala Game (APIO17_koala) C++14
82 / 100
20 ms 464 KB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;
using pii=array<int,2>;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
const int N=105;
int B[N],R[N];
int minValue(int n,int w){
	B[0]=1;
	playRound(B,R);
	for(int i=0;i<n;i++) if(B[i]>=R[i]) return i;
	return 0;
}
int maxValue(int n,int w){
	vector<int> V;
	for(int i=0;i<n;i++) V.push_back(i);
	while(V.size()>1){
		int m=V.size();
		for(int i=0;i<n;i++) B[i]=0;
		for(int i: V) B[i]=w/m;
		playRound(B,R);
		vector<int> NV;
		for(int i: V) if(R[i]>B[i]) NV.push_back(i);
		V=NV;
	}
	return V[0];
}
int greaterValue(int n,int w){
	
}
int odr[N],to[N][2],m;
vector<int> V[N];
void Do(int n,int p,int q,int W){
	for(int i=0;i<n;i++){
		if(p<=odr[i]&&odr[i]<=q) B[i]=W;
		else B[i]=0;
	}
	playRound(B,R);
	for(int i=1;i<=n;i++) to[i][0]=to[i][1]=0;
	for(int i=0;i<n;i++){
		if(B[i]<R[i]) to[odr[i]][0]++;
		else to[odr[i]][1]++;
	}
	m=0;
	for(int i=1;i<=n;i++){
		if(to[i][0]) to[i][0]=++m;
		if(to[i][1]) to[i][1]=++m;
	}
	for(int i=1;i<=n;i++) V[i].clear();
	for(int i=0;i<n;i++){
		if(B[i]<R[i]) odr[i]=to[odr[i]][0];
		else odr[i]=to[odr[i]][1];
		V[odr[i]].push_back(i);
	}
}
pii sim(int n,int w,int p,int q){
	int cnt=0;
	for(int i=0;i<n;i++) if(p<=odr[i]&&odr[i]<=q) cnt++;
	int m=0,val[N];
	for(int i=n;i>=1;i--) for(int x: V[i]) val[x]=++m;
	vector<int> X,Y;
	for(int i=0;i<n;i++){
		if(p<=odr[i]&&odr[i]<=q) X.push_back(i);
		else Y.push_back(i);
	}
	sort(X.begin(),X.end(),[&](int i,int j){
		return val[i]>val[j];
	});
	sort(Y.begin(),Y.end(),[&](int i,int j){
		return val[i]>val[j];
	});
	pii opt{0,-1};
	for(int W=1;W<=w/cnt;W++){
		int bval=-1,s=0,a=-1,b=-1,c=0;
		for(int i=0;i<(int)Y.size();i++) s+=val[Y[i]];
		for(int i=-1,j=(int)Y.size()-1;i<(int)X.size();i++){
			if((W+1)*(i+1)>w) break;
			if(i>=0) s+=val[X[i]];
			while((W+1)*(i+1)+(j+1)>w){
				s-=val[Y[j]];
				j--;
			}
			if(bval<=s){
				if(bval==s) c++;
				else c=0;
				bval=s;
				a=i;
				b=j;
			}
		}
		if(c) continue;
		for(int i=0;i<n;i++) R[i]=0;
		for(int i=0;i<=a;i++) R[X[i]]=B[X[i]]+1;
		for(int i=0;i<=b;i++) R[Y[i]]=B[Y[i]]+1;
		for(int i=1;i<=n;i++) to[i][0]=to[i][1]=0;
		for(int i=0;i<n;i++){
			if(B[i]<R[i]) to[odr[i]][0]++;
			else to[odr[i]][1]++;
		}
		int div=0;
		for(int i=1;i<=n;i++) div+=min(to[i][0],to[i][1]);
		if(div>opt[0]){
			opt[0]=div;
			opt[1]=W;
		}
	}
	return opt;
}
void allValues(int n,int w,int *P){
	for(int i=1;i<=n;i++) V[i].clear();
	for(int i=0;i<n;i++){
		odr[i]=1;
		V[1].push_back(i);
	}
	while(V[n].empty()){
		int p=1;
		while((int)V[p].size()==1) p++;
		int opt=0,val=-1e9,W=0;
		for(int q=p;V[q].size();q++){
			pii res=sim(n,w,p,q);
			if(val<res[0]){
				opt=q;
				val=res[0];
				W=res[1];
			}
		}
		Do(n,p,opt,W);
	}
	for(int i=0;i<n;i++) P[i]=n+1-odr[i];
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:34:1: warning: no return statement in function returning non-void [-Wreturn-type]
   34 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 344 KB Output is correct
2 Correct 20 ms 460 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 18 ms 340 KB Output is correct
5 Correct 18 ms 344 KB Output is correct
6 Correct 18 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 18 ms 344 KB Output is correct
10 Correct 20 ms 344 KB Output is correct
11 Correct 18 ms 344 KB Output is correct
12 Correct 15 ms 344 KB Output is correct
13 Correct 18 ms 464 KB Output is correct
14 Correct 16 ms 456 KB Output is correct
15 Correct 16 ms 344 KB Output is correct
16 Correct 17 ms 344 KB Output is correct
17 Correct 16 ms 460 KB Output is correct
18 Correct 16 ms 344 KB Output is correct
19 Correct 17 ms 344 KB Output is correct
20 Correct 17 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 10 ms 460 KB Output is correct
3 Correct 13 ms 344 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
5 Correct 10 ms 456 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 11 ms 344 KB Output is correct
10 Correct 11 ms 456 KB Output is correct
11 Correct 11 ms 344 KB Output is correct
12 Correct 8 ms 344 KB Output is correct
13 Correct 10 ms 456 KB Output is correct
14 Correct 11 ms 344 KB Output is correct
15 Correct 10 ms 460 KB Output is correct
16 Correct 11 ms 340 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 10 ms 344 KB Output is correct
19 Correct 10 ms 464 KB Output is correct
20 Correct 15 ms 344 KB Output is correct
21 Correct 13 ms 460 KB Output is correct
22 Correct 13 ms 344 KB Output is correct
23 Correct 9 ms 344 KB Output is correct
24 Correct 11 ms 344 KB Output is correct
25 Correct 11 ms 340 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 11 ms 464 KB Output is correct
28 Correct 12 ms 344 KB Output is correct
29 Correct 11 ms 460 KB Output is correct
30 Correct 11 ms 344 KB Output is correct
31 Correct 10 ms 452 KB Output is correct
32 Correct 11 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 10 ms 344 KB Output is correct
35 Correct 12 ms 344 KB Output is correct
36 Correct 10 ms 344 KB Output is correct
37 Correct 10 ms 460 KB Output is correct
38 Correct 9 ms 460 KB Output is correct
39 Correct 12 ms 460 KB Output is correct
40 Correct 11 ms 456 KB Output is correct