QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732652 | #9565. Birthday Gift | mhw# | RE | 0ms | 3624kb | C++23 | 1.9kb | 2024-11-10 15:25:59 | 2024-11-10 15:26:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
ll n; string s; cin >> s; n = s.size(); s = " " + s;
vector<int> a;
for(int i = 1; i <= n; ++i) {
if(a.size() && s[i] - '0' == a.back() && s[i] - '0' != 2) a.pop_back();
else a.push_back(s[i] - '0');
if(a.size() > 3) {
int x = a[(int)a.size() - 1], y = a[(int)a.size() - 2], z = a[(int)a.size() - 3];
if(y == 2 && ((x == 0 && z == 1) || (x == 1 && z == 0))) {
a.pop_back(), a.pop_back(), a.pop_back(), a.push_back(2);
}
}
// cout << "check: ";for(auto x:a) cout << x << " "; cout << endl;
}
//0100202010
//022010
//0220101221
vector<int> ans[2];
ll cnt[2];
for(auto x:a) {
if(!ans[0].size()) {
ans[0].push_back(x);
} else {
if((x == ans[0].back() && x != 2) || (x != ans[0].back() && (x == 2 || ans[0].back() == 2) )) {
ans[0].pop_back();
} else {
ans[0].push_back(x);
}
}
}
if(ans[0][0] == 2) {
cnt[0] = ans[0].size() % 2;
} else {
cnt[0] = ans[0].size();
}
reverse(a.begin(), a.end());
for(auto x:a) {
if(!ans[1].size()) {
ans[1].push_back(x);
} else {
if((x == ans[1].back() && x != 2) || (x != ans[1].back() && (x == 2 || ans[1].back() == 2) )) {
ans[1].pop_back();
} else {
ans[1].push_back(x);
}
}
}
if(ans[1][0] == 2) {
cnt[1] = ans[1].size() % 2;
} else {
cnt[1] = ans[1].size();
}
cout << min(cnt[0], cnt[1]) << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
5 0110101 01020102 0000021111 1012121010 0100202010
output:
3 4 0 6 0
result:
ok 5 number(s): "3 4 0 6 0"
Test #2:
score: -100
Runtime Error
input:
50000 1010110101 1010101010 0101010101 0101010010 0101010010 1010101010 0101001010 1010010010 0100101010 1010101001 1010100101 0101010100 0100101011 0101101010 1011010110 1011010101 1010010101 1010010010 0101010101 0010101010 0101011010 0100101010 1010101010 1010010101 1010101101 1101010101 10100101...