/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 26ms 548.0 KiB

Code

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int maxConsecutiveOnes(string s) {
    int maxCount = 0, currentCount = 0, totalOnes = 0;
    vector<int> counts;

    for (char c : s) {
        if (c == '1') {
            currentCount++;
        } else {
            if (currentCount > 0) {
                counts.push_back(currentCount);
                totalOnes += currentCount;
                currentCount = 0;
            }
        }
    }
    if (currentCount > 0) {
        counts.push_back(currentCount);
        totalOnes += currentCount;
    }

    if (counts.empty()) return 0;

    maxCount = counts[0];
    for (size_t i = 0; i < counts.size(); ++i) {
        maxCount = max(maxCount, counts[i]);
        if (i < counts.size() - 1) {
            maxCount = max(maxCount, counts[i] + counts[i + 1]);
        }
    }

    int numberOfFlips = s.length() - totalOnes;
    if (numberOfFlips >= 1) {
        maxCount = max(maxCount, totalOnes + numberOfFlips);
    }

    return maxCount;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        string S;
        cin >> S;
        int result = maxConsecutiveOnes(S);
        cout << result << endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Contest
Brain Booster #7
Language
C++11 (G++ 13.2.0)
Submit At
2024-11-05 15:04:56
Judged At
2024-11-11 02:31:37
Judged By
Score
0
Total Time
26ms
Peak Memory
548.0 KiB