/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Wrong Answer 23ms 568.0 KiB
#3 Wrong Answer 5ms 376.0 KiB

Code

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        int N;
        string S;
        cin >> N >> S;
        
        vector<int> segments;
        int count = 0;
        
        for (int i = 0; i < N; ++i) {
            if (S[i] == '1') {
                ++count;
            } else {
                if (count > 0) {
                    segments.push_back(count);
                }
                count = 0;
            }
        }
        if (count > 0) {
            segments.push_back(count);
        }

        sort(segments.rbegin(), segments.rend());

        int max_consecutive_1s = 0;
        for (int i = 0; i < segments.size(); i += 2) {
            max_consecutive_1s += segments[i];
        }

        cout << max_consecutive_1s << 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:20:32
Judged At
2024-11-11 02:30:51
Judged By
Score
5
Total Time
23ms
Peak Memory
568.0 KiB