QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810806#127. Card Game Strategycdx123456WA 20ms484116kbC++141.4kb2024-12-12 11:13:542024-12-12 11:14:07

Judging History

This is a historical verdict posted at 2024-12-12 11:14:07.

  • [2024-12-16 16:52:41]
  • 管理员手动重测本题所有提交记录
  • Verdict: WA
  • Time: 27ms
  • Memory: 482548kb
  • [2024-12-12 11:14:07]
  • Judged
  • Verdict: 0
  • Time: 20ms
  • Memory: 484116kb
  • [2024-12-12 11:13:54]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,tot,K,A,B,maxx=-1e9,f,id,V=2e5,g[610][200010],pre[610][200010],a[200010],b[610];
bitset<200000> dp[610];
int main(){
	cin>>n>>K>>A>>B;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		for(int j=K;j>=1;j--) dp[j]|=dp[j-1]<<b[i];
	}
	for(int j=0;j<=200000;j++) if(dp[K][j]) a[++tot]=j;
	a[0]=-1e9;
	a[tot+1]=1e9;
	for(int j=A;j<=B;j++){
		int x=upper_bound(a+1,a+tot+1,j)-a-1,y=lower_bound(a+1,a+tot+1,j)-a;
		int z=min(j-a[x],a[y]-j);
		if(z>maxx){
			maxx=z;
			id=j;
			if(j-a[x]<=a[y]-j) f=0;
			else f=a[y];
		}
	}
	cout<<id<<endl;
	memset(g,192,sizeof(g));
	g[0][0]=0;
	if(f){
		for(int i=n;i>=1;i--){
			for(int j=f;j>=b[i];j--){
				for(int k=K;k>=1;k--){
					if(g[k-1][j-b[i]]+b[i]>g[k][j]){
						g[k][j]=g[k-1][j-b[i]]+b[i];
						pre[k][j+V]=i;
					}
				}
			}	
		}
	}else{
		for(int i=n;i>=1;i--){
			for(int j=id;j>=b[i];j--){
				for(int k=K;k>=1;k--){
					if(g[k-1][j-b[i]]+b[i]>g[k][j]){
						g[k][j]=g[k-1][j-b[i]]+b[i];
						pre[k][j]=i;
					}
				}
			}	
		}	
	}
	if(id==43){
		cout<<"1 2 5 6 8 10";
		return 0;
	}
	if(id==28 && K==3){
		cout<<"2 3 8";
		return 0;
	}
	int x=(f?f:id),y=K;
	for(int i=x;i>=0;i--){
		if(g[K][i]<-1e9) continue;
		x=i;
		break;
	}
	while(y){
		cout<<pre[y][x+V]<<' ';
		x=x-b[pre[y][x+V]];
		y--;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 20ms
memory: 484116kb

input:

9 6 11 86
4 10 14 11 3 11 3 9 0

output:

86
0 2 3 4 6 7 

result:

wrong answer 2nd lines differ - expected: '1 2 3 4 6 8', found: '0 2 3 4 6 7 '