QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661111 | #8776. Not Another Constructive! | comeintocalm# | WA | 1ms | 4640kb | C++20 | 1.1kb | 2024-10-20 14:44:54 | 2024-10-20 14:45:01 |
Judging History
answer
#include <bits/stdc++.h>
bool vis[41][41][401][2501];
char s[45];
int n, m;
bool dfs(int i, int x, int y, int z) {
if (z > m) {
return false;
}
if (i >= n) {
return false;
}
if (z == m) {
for (int j = 1; j <= n; ++j) {
if (s[j] == '?') {
s[j] = 'B';
}
}
printf("%s", s + 1);
exit(0);
}
if (vis[i][x][y][z]) {
return false;
}
vis[i][x][y][z] = true;
if (s[i + 1] != '?') {
if (s[i + 1] == 'N') {
dfs(i + 1, x + 1, y, z);
} else if (s[i + 1] == 'A') {
dfs(i + 1, x, y + x, z);
} else if (s[i + 1] == 'C') {
dfs(i + 1, x, y, z + y);
} else {
dfs(i + 1, x, y, z);
}
} else {
s[i + 1] = 'N';
dfs(i + 1, x + 1, y, z);
s[i + 1] = 'A';
dfs(i + 1, x, y + x, z);
s[i + 1] = 'C';
dfs(i + 1, x, y, z + y);
s[i + 1] = 'B';
dfs(i + 1, x, y, z);
s[i + 1] = '?';
}
return false;
}
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
bool ans = dfs(0, 0, 0, 0);
if (!ans) {
puts("-1");
} else {
printf("%s", s + 1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4640kb
input:
22 2 N??A??????C???????????
output:
NNCANNNNNNCBBBBBBBBBBB
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
1 0 ?
output:
B
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
1 0 N
output:
N
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
1 0 X
output:
X
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
1 1 ?
output:
-1
result:
ok correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 1 N
output:
-1
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
1 1 X
output:
-1
result:
ok correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
2 0 ??
output:
BB
result:
ok correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
2 0 N?
output:
NB
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
2 0 ?C
output:
BC
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
2 1 N?
output:
-1
result:
ok correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
2 1 ?C
output:
-1
result:
ok correct
Test #15:
score: -100
Wrong Answer
time: 0ms
memory: 3884kb
input:
3 1 ???
output:
-1
result:
wrong answer returned false