QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546623#8776. Not Another Constructive!chengning0909RE 2ms10236kbC++141.7kb2024-09-04 10:18:372024-09-04 10:18:39

Judging History

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

  • [2024-09-04 10:18:39]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:10236kb
  • [2024-09-04 10:18:37]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using tpl = tuple<int, int, int, int>;

const int N = 45, M = 405, MAXK = 2510;

int n, k;
string s;
bitset<MAXK> dp[N][N][M];
tpl tp;
bool flag;

void print(tpl x) {
    auto [i, j, t, p] = x;
    if (!i) return ;
    if ((s[i] == 'N' || s[i] == '?') && dp[i - 1][j - 1][t][p]) {
        print({i - 1, j - 1, t, p}), cout << 'N';
    } else if ((s[i] == 'A' || s[i] == '?') && dp[i - 1][j][t - j][p]) {
        print({i - 1, j, t - j, p}), cout << 'A';
    } else if ((s[i] == 'C' || s[i] == '?') && dp[i - 1][j][t][p - t]) {
        print({i - 1, j, t, p - t}), cout << 'C';
    } else if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C' && dp[i - 1][j][t][p]) {
        print({i - 1, j, t, p}), cout << (s[i] == '?' ? 'B' : s[i]);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k >> s, s = ' ' + s;
    dp[0][0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            for (int t = 0; t <= (i - 1) * i / 4; t++) {
                if (s[i] == 'N' || s[i] == '?') dp[i][j + 1][t] |= dp[i - 1][j][t];
                if (s[i] == 'A' || s[i] == '?') if (t + j < M) dp[i][j][t + j] |= dp[i - 1][j][t];
                if (s[i] == 'C' || s[i] == '?') dp[i][j][t] |= (dp[i - 1][j][t] << t);
                if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C') dp[i][j][t] |= dp[i - 1][j][t];
            }
        }
        if (i == n) {
            for (int j = 0; j <= i; j++) {
                for (int t = 0; t <= (i + 1) * i / 4; t++) {
                    if (dp[i][j][t][k]) flag = 1, tp = {i, j, t, k};
                }
            }
        }
    }
    if (!flag) cout << -1;
    else print(tp);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 10236kb

input:

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

output:

NCNANNNNNNCNNNNNNNNNNN

result:

ok correct

Test #2:

score: 0
Accepted
time: 2ms
memory: 6632kb

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

1 0
?

output:

N

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

1 0
N

output:

N

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

1 0
X

output:

X

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

2 0
??

output:

NN

result:

ok correct

Test #11:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

2 0
N?

output:

NN

result:

ok correct

Test #12:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

2 0
?C

output:

NC

result:

ok correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

4 1
????

output:

NACN

result:

ok correct

Test #23:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

4 1
N???

output:

NACN

result:

ok correct

Test #27:

score: -100
Runtime Error

input:

4 1
?N??

output:


result: