QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#73729 | #4273. Good Game | 12345678 | 0 | 17ms | 67156kb | C++14 | 2.4kb | 2023-01-27 20:14:04 | 2023-01-27 20:14:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define inf 1e9
#define pii pair <int, int>
const int mod = 1e9 + 7;
inline int read () {
int x = 0, f = 1;
char ch = getchar ();
while (ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar ();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ();
return x * f;
}
inline void write (int x) {
if (x < 0) x = -x, putchar ('-');
if (x >= 10) write (x / 10);
putchar (x % 10 + '0');
}
int n;
char ch[1000005];
int tot;
pii a[1000005];
vector <pii> Ans;
int f[1000005][3], pre[1000005][3];
signed main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
n = read();
scanf("%s", ch + 1);
a[tot = 1] = mp((ch[1] == 'A') ? 0 : 1, 1);
for(int i = 2; i <= n; i++) {
if(ch[i] != ch[i-1]) a[++tot] = mp((ch[i] == 'A') ? 0 : 1, 1);
else a[tot].second++;
}
f[0][0] = 1;
for(int i = 0; i <= tot; i++) f[i][1] = f[i][2] = inf;
for(int i = 1; i <= tot; i++) {
if(f[i-1][0]) {
if(a[i].second >= 2) f[i][0] = 1, pre[i][0] = 0;
if(!a[i].first) f[i][1] = 1, pre[i][1] = 0;
else f[i][2] = 1, pre[i][2] = 0;
}
if(f[i-1][1] != inf) {
if(!a[i].first) {
if(f[i-1][1] == 1) {
f[i][0] = 1, pre[i][0] = 1;
if(f[i-1][1] < f[i][1]) f[i][1] = f[i-1][1], pre[i][1] = 1;
}
else {
if(f[i-1][1] < f[i][1]) f[i][1] = f[i-1][1], pre[i][1] = 1;
if(f[i-1][1] - 1 < f[i][2]) f[i][2] = f[i-1][1] - 1, pre[i][2] = 1;
}
}
else {
if(f[i-1][1] + 1 < f[i][2]) f[i][2] = f[i-1][1] + 1, pre[i][2] = 1;
if(a[i].second >= 2 && f[i-1][1] < f[i][1]) f[i][1] = f[i-1][1], pre[i][1] = 1;
}
}
if(f[i-1][2] != inf) {
if(a[i].first) {
if(f[i-1][2] == 1) {
f[i][0] = 1, pre[i][0] = 2;
if(f[i-1][2] < f[i][2]) f[i][2] = f[i-1][2], pre[i][2] = 2;
}
else {
if(f[i-1][2] < f[i][2]) f[i][2] = f[i-1][2], pre[i][2] = 2;
if(f[i-1][2] - 1 < f[i][1]) f[i][1] = f[i-1][2] - 1, pre[i][1] = 2;
}
}
else {
if(f[i-1][2] + 1 < f[i][1]) f[i][1] = f[i-1][2] + 1, pre[i][1] = 2;
if(a[i].second >= 2 && f[i-1][2] < f[i][2]) f[i][2] = f[i-1][2], pre[i][2] = 2;
}
}
}
if(!f[tot][0]) return printf("-1\n") & 0;
write((int)Ans.size()), putchar('\n');
for(auto x : Ans) write(x.first), putchar(' '), write(x.second), putchar('\n');
return 0;
}
/*
*/
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5504kb
input:
9 ABAABBBAA
output:
0
result:
wrong answer the string has not been fully deleted
Subtask #2:
score: 0
Wrong Answer
Test #51:
score: 6
Accepted
time: 0ms
memory: 3528kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
ok no solution
Test #52:
score: 0
Accepted
time: 2ms
memory: 3464kb
input:
300 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...
output:
-1
result:
ok no solution
Test #53:
score: -6
Wrong Answer
time: 0ms
memory: 3548kb
input:
299 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #3:
score: 0
Wrong Answer
Test #102:
score: 0
Wrong Answer
time: 2ms
memory: 3856kb
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #4:
score: 0
Wrong Answer
Test #153:
score: 0
Wrong Answer
time: 17ms
memory: 67156kb
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
wrong answer you didn't find a solution but jury did