/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 27ms 552.0 KiB
#3 Wrong Answer 7ms 480.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;
}

long long res2(int H, int W){
    int mini = min(H,W);
    long long tot = 0;
    for(int k=1; k<=mini; k++){
        tot += (long long)(H-k+1)*(W-k+1);
    }
    return tot;
}
int main(){
    int H,W;
    cin>>H>>W;
    cout<<res2(H,W)<<endl;
    return 0;
}

bool cnfrm (vector<int>& height, int start , int k){
    vector<int> segment(height.begin()+start, height.begin()+start+k);
    sort(segment.begin(), segment.end());
    for(int i=1; i<k; i++){
        if(segment[i] < segment[i-1]){
            return false;
        }
    }
    return true;
}

void res3(int n, int k, vector<int>& height){
    for(int i=0; i<=n-k; i++){
        if(cnfrm(height,i,k)){
            cout<<"YES\n"<< i+1 <<" "<<i+k<<endl;
            return;
        }
    }
    cout<<"NO\n";
}
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> height(n);
    for(int i=0; i<n; i++){
        cin>>height[i];
    }
    res3(n,k,height);
    return 0;

}
*/

int res22(string &s){
    int n = s.size();
    vector<int> zero;
    int maxi = 0;

    int zeroCNT = 0;
    for(char c:s){
        if(c == '0'){
            zeroCNT++;
        }
        else{
            if(zeroCNT>0){
                zero.push_back(zeroCNT);
                zeroCNT = 0;
            }
        }
    }
    if(zeroCNT>0){
        zero.push_back(zeroCNT);
    }
    sort(zero.rbegin(), zero.rend());
    for(int i=0; i<zero.size(); i+=2){
        maxi += zero[i];
    }
    return maxi;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        string s;
        cin>>n>>s;
        cout<<res22(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 15:23:54
Judged At
2024-11-11 02:30:45
Judged By
Score
5
Total Time
27ms
Peak Memory
552.0 KiB