QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#460607#8832. Daily DisinfectionQwertyPi#WA 1ms3724kbC++14891b2024-07-01 21:32:082024-07-01 21:32:08

Judging History

你现在查看的是最新测评结果

  • [2024-07-01 21:32:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3724kb
  • [2024-07-01 21:32:08]
  • 提交

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'