QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732697 | #9565. Birthday Gift | Lzy_# | WA | 0ms | 3500kb | C++14 | 2.2kb | 2024-11-10 15:36:47 | 2024-11-10 15:36:47 |
Judging History
answer
#include <bits/stdc++.h>
void solve() {
std::string s;
std::cin >> s;
int l1 = -1, r1 = -1;
int l2 = -1, r2 = -1;
if (s[0] == '0') {
l2 = r2 = 1;
} else {
if (s[0] == '1') {
l1 = r1 = 1;
} else {
l1 = r1 = l2 = r2 = 1;
}
}
for (int i = 1; i < s.size(); ++ i) {
int tl1 = l1, tr1 = r1, tl2 = l2, tr2 = r2;
if (s[i] == '0') {
if (tl1 != -1) {
l2 = tl1 + 1;
} else {
l2 = -1;
}
if (tr1 != -1) {
r2 = tr1 + 1;
} else {
r2 = -1;
}
if (tl2 > 0) {
l1 = tl2 - 1;
} else {
l1 = -1;
}
if (tr2 > 0) {
r1 = tr2 - 1;
} else {
r1 = -1;
}
} else {
if (s[i] == '1') {
if (tl2 != -1) {
l1 = tl2 + 1;
} else {
l1 = -1;
}
if (tr2 != -1) {
r1 = tr2 + 1;
} else {
r1 = -1;
}
if (tl1 > 0) {
l2 = tl1 - 1;
} else {
l2 = -1;
}
if (tr1 > 0) {
r2 = tr1 - 1;
} else {
r2 = -1;
}
} else {
if (tl1 > 0) {
l2 = tl1 - 1;
} else {
if (tl1 == 0) {
l2 = 1;
} else {
l2 = -1;
}
}
if (tl2 > 0) {
l1 = tl2 - 1;
} else {
if (tl2 == 0) {
l1 = 1;
} else {
l1 = -1;
}
}
if (tr1 != -1) {
r2 = tr1 + 1;
} else {
r2 = -1;
}
if (tr2 != -1) {
r1 = tr2 + 1;
} else {
r1 = -1;
}
}
}
if (l1 == 0 || l2 == 0 || r1 == 0 || r2 == 0) {
if (l1 == -1) {
l1 = 0;
}
if (l2 == -1) {
l2 = 0;
}
if (r1 == -1) {
r1 = 0;
}
if (r2 == -1) {
r2 = 0;
}
}
if (r1 && l1 == -1) {
l1 = 0;
}
if (r2 && l2 == -1) {
l2 = 0;
}
//std::cout << l1 << " " << r1 << " " << l2 << " " << r2 << '\n';
}
int ans = 1 << 30;
if (l1 != -1) {
ans = std::min(ans, l1);
}
if (l2 != -1) {
ans = std::min(ans, l2);
}
if (r1 != -1) {
ans = std::min(ans, r1);
}
if (r2 != -1) {
ans = std::min(ans, r2);
}
std::cout << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0); std::cout.tie(0);
int T;
std::cin >> T;
while (T --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3500kb
input:
5 0110101 01020102 0000021111 1012121010 0100202010
output:
0 1 1 0 0
result:
wrong answer 1st numbers differ - expected: '3', found: '0'