QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#496476 | #8776. Not Another Constructive! | sqrtqwq | WA | 1ms | 5372kb | C++14 | 1.2kb | 2024-07-28 11:09:32 | 2024-07-28 11:09:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bitset<2510> dp[45][45][45];
int n,m;char ans[45];
int main()
{
string str;
cin >> n >> m >> str;str = " " + str;
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: 100
Accepted
time: 0ms
memory: 5372kb
input:
22 2 N??A??????C???????????
output:
NCNANNNNNNCNNNNNNNNNNN
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 4708kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
1 0 ?
output:
C
result:
ok correct
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
1 0 N
output:
-1
result:
wrong answer returned false