QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#525885 | #6338. Chorus | Qwerty1232# | 16 | 27ms | 7324kb | C++23 | 1.6kb | 2024-08-21 01:44:18 | 2024-08-21 01:44:19 |
Judging History
answer
#include <bits/stdc++.h>
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::string s;
std::cin >> n >> k >> s;
int mask_s = 0;
for (int i = 0; i < 2 * n; i++) {
mask_s |= int(s[i] == 'A') << i;
}
std::vector<int> dist(1 << 2 * n, 1e9);
dist[mask_s] = 0;
for (int i = (1 << 2 * n) - 1; i >= 0; i--) {
if (dist[i] >= 1e8) {
continue;
}
for (int j = 0; j + 1 < 2 * n; j++) {
if (!(i >> j & 1) && (i >> j + 1 & 1)) {
dist[i ^ 3 << j] = std::min(dist[i ^ 3 << j], dist[i] + 1);
}
}
}
int ans = 1e9;
for (int i = 0; i < (1 << 2 * n); i++) {
if (dist[i] < 1e8) {
std::string s(2 * n, '-');
for (int j = 0; j < 2 * n; j++) {
s[j] = "BA"[i >> j & 1];
}
int cnt = 0;
while (s.size()) {
cnt++;
int it = std::find(s.begin(), s.end(), 'B') - s.begin();
if (it == 0) {
cnt = 1e9;
break;
}
s.erase(s.begin(), s.begin() + it);
for (auto& ch : s) {
if (it && ch == 'B') {
ch = '-';
it--;
}
}
std::erase(s, '-');
}
if (cnt <= k) {
ans = std::min(ans, dist[i]);
}
}
}
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 16
Accepted
Test #1:
score: 16
Accepted
time: 0ms
memory: 3608kb
input:
1 1 BA
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 16
Accepted
time: 1ms
memory: 3592kb
input:
7 5 ABBAAABBABABBA
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 16
Accepted
time: 11ms
memory: 7228kb
input:
10 3 BABBABAABAABBABBBAAA
output:
26
result:
ok 1 number(s): "26"
Test #4:
score: 16
Accepted
time: 3ms
memory: 7224kb
input:
10 2 AAABBABABBAAABBBAABB
output:
11
result:
ok 1 number(s): "11"
Test #5:
score: 16
Accepted
time: 27ms
memory: 7204kb
input:
10 1 BBBBBBBBBBAAAAAAAAAA
output:
100
result:
ok 1 number(s): "100"
Test #6:
score: 16
Accepted
time: 26ms
memory: 7200kb
input:
10 2 BBBBBBBBBBAAAAAAAAAA
output:
75
result:
ok 1 number(s): "75"
Test #7:
score: 16
Accepted
time: 23ms
memory: 7196kb
input:
10 9 BBBBBBBBBBAAAAAAAAAA
output:
56
result:
ok 1 number(s): "56"
Test #8:
score: 16
Accepted
time: 27ms
memory: 7232kb
input:
10 10 BBBBBBBBBBAAAAAAAAAA
output:
55
result:
ok 1 number(s): "55"
Test #9:
score: 16
Accepted
time: 3ms
memory: 7312kb
input:
10 10 ABABABABABABABABABAB
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 16
Accepted
time: 4ms
memory: 7260kb
input:
10 2 ABAAABABABBBABABABAB
output:
14
result:
ok 1 number(s): "14"
Test #11:
score: 16
Accepted
time: 4ms
memory: 7324kb
input:
10 4 ABAABBAAABBBAAABBBAB
output:
2
result:
ok 1 number(s): "2"
Test #12:
score: 16
Accepted
time: 4ms
memory: 7252kb
input:
10 4 ABAAABBBAAABBBAABBAB
output:
2
result:
ok 1 number(s): "2"
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 3784kb
input:
179 54 AAABABABABBAAABBABBABBABBBAAABAAAAABBBABAAAAABABBBAABBBABABBAABABAABABBBBABAABAABABABBBABBAABABBAABBAABABBAAABAAAAAAAABBAAAAABAAABBBBBBBABBAABBBABABAABBAABBABABABBABAAABABAAABABABBAABABAAABBABABABABABBAAABABBBBBBBAABBBAABABBBBABAABBAAAABAABBABABAABAAABABAAAABBBAABAAABBABABBBABAAABAABBBABBBBBA...
output:
1000000000
result:
wrong answer 1st numbers differ - expected: '41', found: '1000000000'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%