QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121608 | #4273. Good Game | bashkort# | 0 | 5ms | 3796kb | C++20 | 2.1kb | 2023-07-08 15:30:27 | 2024-07-04 00:31:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
vector<pair<int, int>> ans;
while (size(s) > 1) {
int cntf = 1;
while (cntf < size(s) && s[cntf] != s[cntf - 1]) {
cntf += 1;
}
int cntb = 1;
while (cntb < size(s) && s.rbegin()[cntb] != s.rbegin()[cntb - 1]) {
cntb += 1;
}
int siz = size(s);
if (cntf >= cntb) {
for (int i = 1; i < size(s); ++i) {
if (s[i] == s[i - 1]) {
int j = i;
while (j < size(s) && s[i] == s[j]) {
j += 1;
}
int len = j - (i - 1);
while (len > 3) {
ans.push_back({i, 2});
len -= 2;
}
ans.push_back({i, len});
s.erase(s.begin() + i - 1, s.begin() + j);
break;
}
}
} else {
for (int i = 1; i < size(s); ++i) {
if (s.rbegin()[i] == s.rbegin()[i - 1]) {
int j = i;
while (j < size(s) && s.rbegin()[i] == s.rbegin()[j]) {
j += 1;
}
int len = j - (i - 1);
j = size(s) - j, i = size(s) - i;
while (len > 3) {
ans.push_back({j + 1, 2});
len -= 2;
}
ans.push_back({j + 1, len});
s.erase(s.begin() + j, s.begin() + i + 1);
break;
}
}
}
if (size(s) == siz) {
break;
}
}
if (!s.empty()) {
cout << -1 << '\n';
return 0;
}
cout << size(ans) << '\n';
for (auto [l, r] : ans) {
cout << l << " " << r << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3584kb
input:
9 ABAABBBAA
output:
4 3 2 2 2 2 2 1 3
result:
ok good solution!
Test #2:
score: 3
Accepted
time: 0ms
memory: 3468kb
input:
13 ABABBABABBABA
output:
6 4 2 7 2 3 2 4 2 2 3 1 2
result:
ok good solution!
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 3696kb
input:
15 AABABAABABAABAB
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #2:
score: 0
Wrong Answer
Test #51:
score: 6
Accepted
time: 0ms
memory: 3492kb
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
-1
result:
ok no solution
Test #52:
score: 6
Accepted
time: 0ms
memory: 3768kb
input:
300 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAAB...
output:
-1
result:
ok no solution
Test #53:
score: 6
Accepted
time: 0ms
memory: 3588kb
input:
299 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
149 96 2 96 2 96 2 96 2 191 2 191 2 191 2 95 2 188 2 94 2 185 2 93 2 182 2 92 2 179 2 91 2 176 2 90 2 173 2 89 2 170 2 88 2 167 2 87 2 164 2 86 2 161 2 85 2 158 2 84 2 155 2 83 2 152 2 82 2 149 2 81 2 146 2 80 2 143 2 79 2 140 2 78 2 137 2 77 2 134 2 76 2 131 2 75 2 128 2 74 2 125 2 73 2 122 2 72 2 ...
result:
ok good solution!
Test #54:
score: 0
Wrong Answer
time: 0ms
memory: 3684kb
input:
299 BBBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #3:
score: 0
Wrong Answer
Test #102:
score: 7
Accepted
time: 5ms
memory: 3796kb
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
2998 1996 2 1996 2 3991 2 3991 2 3991 2 3991 3 1995 2 3988 2 1994 2 3985 2 1993 2 3982 2 1992 2 3979 2 1991 2 3976 2 1990 2 3973 2 1989 2 3970 2 1988 2 3967 2 1987 2 3964 2 1986 2 3961 2 1985 2 3958 2 1984 2 3955 2 1983 2 3952 2 1982 2 3949 2 1981 2 3946 2 1980 2 3943 2 1979 2 3940 2 1978 2 3937 2 1...
result:
ok good solution!
Test #103:
score: 0
Wrong Answer
time: 2ms
memory: 3588kb
input:
5999 BBBBBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
-1
result:
wrong answer you didn't find a solution but jury did
Subtask #4:
score: 0
Time Limit Exceeded
Test #153:
score: 0
Time Limit Exceeded
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...