QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121606 | #4273. Good Game | bashkort# | 0 | 0ms | 3604kb | C++20 | 2.1kb | 2023-07-08 15:28:33 | 2024-07-04 00:31:14 |
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 = n - j, i = n - 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
Runtime Error
Test #1:
score: 3
Accepted
time: 0ms
memory: 3604kb
input:
9 ABAABBBAA
output:
4 3 2 2 2 2 2 1 3
result:
ok good solution!
Test #2:
score: -3
Runtime Error
input:
13 ABABBABABBABA
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #51:
score: 0
Runtime Error
input:
299 ABABABABABABABABABABABABABABABABABBAABBAABBAABBAAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBAABBBAABBAABBAABBAABBAABBAABBAABBAABBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #102:
score: 0
Runtime Error
input:
5998 BABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #153:
score: 0
Time Limit Exceeded
input:
999997 ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABA...