QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#496459#8776. Not Another Constructive!sqrtqwqWA 1ms5328kbC++141.2kb2024-07-28 10:46:242024-07-28 10:46:24

Judging History

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

  • [2024-07-28 10:46:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5328kb
  • [2024-07-28 10:46:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

bitset<2510> dp[45][45][45];
int n,m;char str[45],ans[45];

int main()
{
	cin >> n >> m >> str + 1;
	for(int i = 1;i <= n;i++)dp[0][0][i][0] = 1;
	for(int i = 1;i <= n;i++)
	{
		for(int j = 0;j <= i;j++)
		{
			for(int k = 0;k <= n - i;k++)
			{
				if(str[i] != 'N' && str[i] != 'A' && str[i] != 'C')dp[i][j][k] |= dp[i - 1][j][k];
				if((str[i] != 'N' && str[i] == '?') && j)dp[i][j][k] |= dp[i - 1][j - 1][k];
				if(str[i] != 'A' && str[i] == '?')dp[i][j][k] |= (dp[i - 1][j][k] << (j * k));
				if(str[i] != 'C' && str[i] == '?')dp[i][j][k] |= dp[i - 1][j][k + 1];
			}
		}
	}
	int res = -1;
	for(int i = 0;i <= n;i++)if(dp[n][i][0][m])res = i;
	if(res == -1)return cout << -1,0;
	for(int i = n,j = res,k = 0,l = m;i >= 1;i--)
	{
		if(str[i] == 'N' || (str[i] == '?' && j && dp[i - 1][j - 1][k][l]))ans[i] = 'N',j--;
		else if(str[i] == 'A' || (str[i] == '?' && j * k <= l && dp[i - 1][j][k][l - j * k]))ans[i] = 'A',l -= j * k;
		else if(str[i] == 'C' || (str[i] == '?' && dp[i - 1][j][k + 1][l]))ans[i] = 'C',k++;
		else ans[i] = str[i];
	}
	for(int i = 1;i <= n;i++)cout << ans[i];
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

-1

result:

wrong answer returned false