/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 27ms 548.0 KiB
#3 Wrong Answer 7ms 324.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

int res(string &s){
    int n = s.size();
    vector<int> gaps;

    int count1 = 0;
    int max1 = 0;
    bool gap = false;

    for(int i=0; i<n; i++){
        if(s[i]=='1'){
            count1++;
            max1 = max(max1,count1);
            gap = false;
        }
        else{
            if(count1>0){
                gaps.push_back(count1);
                count1 = 0;
            }
            gap = true;
        }
    }
    if(count1>0) gaps.push_back(count1);
    sort (gaps.rbegin(),gaps.rend());
    int result=0;
    for(int i=0; i<gaps.size(); i+=2){
        result+=gaps[i];
    }
    return result;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int N;
        string S;
        cin>>N>>S;
        cout<<res(S)<<endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 14:50:09
Judged At
2024-11-11 02:32:24
Judged By
Score
5
Total Time
27ms
Peak Memory
548.0 KiB