QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#460607 | #8832. Daily Disinfection | QwertyPi# | WA | 1ms | 3724kb | C++14 | 891b | 2024-07-01 21:32:08 | 2024-07-01 21:32:08 |
Judging History
answer
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size();
#define int long long
using namespace std;
void solve() {
int n; cin >> n;
string s; cin >> s;
bool extra = s.front() == '1' && s.back() == '1';
vector<int> cts, cts2; int prv = -1, cnt = 0;
for (auto c : s) {
if (prv == c) {
cnt++;
} else {
if (prv == '0') cts.push_back(cnt);
else cts2.push_back(cnt);
cnt = 1; prv = c;
}
}
if (prv == '0') cts.push_back(cnt);
else cts2.push_back(cnt);
extra &= *max_element(all(cts)) == 1;
int ans = count(all(s), '1') + (extra ? *min_element(all(cts2)) : 0);
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); cout.tie(0)->sync_with_stdio(false);
int t; cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3724kb
input:
3 2 01 5 00110 9 101010101
output:
1 2 5
result:
wrong answer 3rd numbers differ - expected: '6', found: '5'