/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 3ms 768.0 KiB
#2 Wrong Answer 24ms 532.0 KiB

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

// Function to calculate maximum consecutive 1s
int maxConsecutiveOnes(string &s) {
    int max_count = 0, count = 0;
    for (char c : s) {
        if (c == '1') {
            count++;
            max_count = max(max_count, count);
        } else {
            count = 0;
        }
    }
    return max_count;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        string s;
        cin >> s;

        // Indices of '0's
        vector<int> zero_indices;
        for (int i = 0; i < n; ++i) {
            if (s[i] == '0') {
                zero_indices.push_back(i);
            }
        }

        // Simulate the game
        int left = 0, right = zero_indices.size() - 1;
        bool roy_turn = true;

        while (left <= right) {
            if (roy_turn) {
                s[zero_indices[left]] = '1';
                left++;
            } else {
                s[zero_indices[right]] = '0';
                right--;
            }
            roy_turn = !roy_turn;
        }

        cout << maxConsecutiveOnes(s) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-06 14:56:04
Judged At
2024-11-06 14:56:04
Judged By
Score
0
Total Time
24ms
Peak Memory
768.0 KiB