QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#496461 | #8776. Not Another Constructive! | sqrtqwq | WA | 0ms | 5332kb | C++14 | 1.2kb | 2024-07-28 10:48:50 | 2024-07-28 10:48:50 |
Judging History
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: 0ms
memory: 5332kb
input:
22 2 N??A??????C???????????
output:
NNAANNNNNNCNNNNNNNNNNN
result:
wrong answer incorrect number of subsequences: 3