QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457650#8832. Daily Disinfectionucup-team045#WA 0ms3524kbC++201.2kb2024-06-29 13:33:252024-06-29 13:33:25

Judging History

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

  • [2024-06-29 13:33:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3524kb
  • [2024-06-29 13:33:25]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n; string s;
        cin >> n >> s;
        int ans = count(s.begin(), s.end(), '1');
        int mn = 1e9;
        for(int i = 0; i < n; i++){
            if (s[i] == '0') continue;
            int j = i;
            while(j + 1 < n and s[j + 1] == '1') j++;
            mn = min(mn, j - i + 1);
            i = j;
        }
        bool ok = false;
        for(int i = 0; i < n; i++){
            if (s[i] == '0') continue;
            int j = i;
            while(j + 1 < n and s[j + 1] == '1') j++;
            if (i - 1 >= 0 and s[i - 1] == '0'){
                swap(s[i - 1], s[j]);
            }
            else if (j + 1 < n and s[j + 1] == '0'){
                swap(s[i], s[j + 1]);
            }
            else{
                ok = true;
                break;
            }
            i = j;
        }
        if (ok) ans += mn;
        cout << ans << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

input:

3
2
01
5
00110
9
101010101

output:

1
2
5

result:

wrong answer 3rd numbers differ - expected: '6', found: '5'