QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#491624#8776. Not Another Constructive!wol_qwqWA 4ms29888kbC++201.0kb2024-07-25 20:34:102024-07-25 20:34:10

Judging History

你现在查看的是最新测评结果

  • [2024-07-25 20:34:10]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:29888kb
  • [2024-07-25 20:34:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=45;
int n,m,p;
string s,s2;
bitset<maxn*maxn*maxn>dp[maxn][maxn][maxn];
int main(){
	cin>>n>>m>>s;
	s=" "+s;
	for(int i=1;i<=n;i++)s2+=' ';
	for(int c=0;c<=n;c++)dp[0][0][c].set(0);
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			for(int l=0;l<=n-i;l++){
				if(s[i]=='N'||s[i]=='?')if(j)dp[i][j][l]|=dp[i-1][j-1][l];
				if(s[i]=='C'||s[i]=='?')dp[i][j][l]|=dp[i-1][j][l+1];
				if(s[i]=='A'||s[i]=='?')dp[i][j][l]|=dp[i-1][j][l]<<j*l;
				if(s[i]^'N'&&s[i]^'C'&&s[i]^'A')dp[i][j][l]|=dp[i-1][j][l];
			}
		}
	}
	while(p<=n&&!dp[n][p][0][m])p++;if(p>n){cout<<-1;return 0;}
	for(int i=n,j=p,k=0,l=m;i;i--)
		if(s[i]=='N'||(s[i]=='?'&&j&&dp[i-1][j-1][k][l])){j--;s2[i-1]='N';}
		else if(s[i]=='C'||(s[i]=='?'&&dp[i-1][j][k+1][l])){k++;s2[i-1]='C';}
		else if(s[i]=='A'||(s[i]=='?'&&l>=j*k&&dp[i-1][j][k][l-j*k])){l-=j*k;s2[i-1]='A';}
		else s2[i]=s[i]=='?'?'B':s[i];
	cout<<s2<<"\n";
	return 0;
}
/*
22 2
N??A??????C???????????
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 29888kb

input:

22 2
N??A??????C???????????

output:

NCCA BBBBBB BBBBBBBBBB

result:

wrong answer incorrect number of subsequences: 0