QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706641 | #8776. Not Another Constructive! | hejinming983282# | WA | 0ms | 7428kb | C++23 | 2.4kb | 2024-11-03 12:45:29 | 2024-11-03 12:45:30 |
Judging History
answer
// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
#define K 2500
using namespace std;
inline int read() {
int now = 0, nev = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
return now * nev;
}
void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
signed main() {
quickio
quickin
quickout
int n, k; cin >> n >> k;
string s; cin >> s;
vector dp(n + 1, vector (n + 1, vector (n + 1, bitset < K + 1 > {})));
for(int i = 0; i <= n; i++)
dp[0][0][i][0] = 1;
for(int i = 0; i < n; i++) {
if(s[i] == '?' || s[i] == 'N') {
for(int N = 0; N <= i; N++)
for(int C = 0; C <= n - i; C++)
dp[i + 1][N + 1][C] |= dp[i][N][C];
}
if(s[i] == '?' || s[i] == 'A') {
for(int N = 0; N <= i; N++)
for(int C = 0; C <= n - i; C++)
dp[i + 1][N][C] |= dp[i][N][C] << (N * C);
}
if(s[i] == '?' || s[i] == 'C') {
for(int N = 0; N <= i; N++)
for(int C = 1; C <= n - i; C++)
dp[i + 1][N][C - 1] |= dp[i][N][C];
}
if(s[i] == '?' || s[i] != 'N' && s[i] != 'A' && s[i] != 'C') {
for(int N = 0; N <= i; N++)
for(int C = 0; C <= n - i; C++)
dp[i + 1][N][C] |= dp[i][N][C];
}
}
int N = -1;
for(int i = 0; i <= n; i++)
if(dp[n][i][0][k]) N = i;
if(N == -1) {
cout << -1 << endl;
return 0;
}
int C = 0;
for(int i = n - 1; i >= 0; i--)
if((s[i] == '?' || s[i] == 'N' && n > 0 && dp[i][N - 1][C][k]))
s[i] = 'N', N--;
else if((s[i] == '?' || s[i] == 'A') && k >= N * C && dp[i][N][C][k - N * C])
s[i] = 'A', k -= N * C;
else if((s[i] == '?' || s[i] == 'C') && dp[i][N][C + 1][k])
s[i] == 'C', C++;
else if(s[i] == '?') s[i] = 'B';
cout << s << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7428kb
input:
22 2 N??A??????C???????????
output:
NNNANNNNNNCNNNNNNNNNNN
result:
wrong answer incorrect number of subsequences: 3