QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#492005#8776. Not Another Constructive!MilkingAnAloeWA 1ms5176kbC++141.3kb2024-07-26 07:38:402024-07-26 07:38:40

Judging History

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

  • [2024-07-26 07:38:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5176kb
  • [2024-07-26 07:38:40]
  • 提交

answer

#include <iostream>
#include <bitset>
#define ll long long
using namespace std;
const int MAXN=45;
bitset<MAXN*MAXN> dp[MAXN][MAXN][MAXN];  
ll n,m;
char a[MAXN],ans[MAXN];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	for (int i=0;i<=n;i++){
		dp[0][0][i].set(0);
	}
	//NAC
	for (int i=1;i<=n;i++){
		for (int j=0;j<=i;j++){
			for (int k=0;k<=n-i;k++){
				if (a[i]=='N' || a[i]=='?'){
					if (j) dp[i][j][k]|=dp[i-1][j-1][k];
				}
				if (a[i]=='C' || a[i]=='?'){
					dp[i][j][k]|=dp[i-1][j][k+1];
				}
				if (a[i]=='A' || a[i]=='?'){
					dp[i][j][k]|=dp[i-1][j][k]<<j*k;
				}
				if (a[i]!='A' && a[i]!='N' && a[i]!='C'){
					dp[i][j][k]|=dp[i-1][j][k];
				}
			}
		}
	}
	ll cntN=0;
	while (cntN<=n && !dp[n][cntN][0][m]){
		++cntN;
	}
	if (cntN==n+1){
		cout<<-1;
		return 0;
	}
	for (int i=n,j=cntN,k=0,seq=m;i>=1;i--){
		if (a[i]=='N' || (a[i]=='?' && j && dp[i-1][j-1][k][seq])) --j,ans[i]='N';
		else if (a[i]=='C' || (a[i]=='?' && k!=n && dp[i-1][j][k+1][seq])) ++j,ans[i]='C';
		else if (a[i]=='A' || (a[i]=='?' && dp[i-1][j][k][seq])) ans[i]='A';
		else{
			if (a[i]=='?')
				ans[i]='S';
			else
				ans[i]=a[i];
		}
	}
	for (int i=1;i<=n;i++){
		cout<<ans[i];
	}
}
/*
22 2
N??A??????C???????????
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5176kb

input:

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

output:

NSSACCNCNNCCNCNCNCNCNC

result:

wrong answer incorrect number of subsequences: 3