/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 512.0 KiB
#2 Wrong Answer 25ms 584.0 KiB

Code

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

using namespace std;

// Function to determine the maximum consecutive 1s in a string
int maxConsecutiveOnes(const 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;
        
        // Vector to store the indices of '0's and '1's
        vector<int> zero_indices, one_indices;
        for (int i = 0; i < n; ++i) {
            if (s[i] == '0') {
                zero_indices.push_back(i);
            } else {
                one_indices.push_back(i);
            }
        }
        
        // Both players play optimally
        int left = 0, right = zero_indices.size() - 1;
        bool roy_turn = true;
        while (left <= right) {
            if (roy_turn) {
                // Roy's turn: flip a '0' to '1'
                s[zero_indices[left]] = '1';
                left++;
            } else {
                // Emon's turn: flip a '1' to '0'
                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:53:29
Judged At
2024-11-11 02:24:54
Judged By
Score
0
Total Time
25ms
Peak Memory
584.0 KiB