/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 328.0 KiB
#2 Wrong Answer 19ms 576.0 KiB

Code

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

int calculate_max_consecutive_ones(string s, int n) {
    int max_consecutive_ones = 0;
    int current_count = 0;

    for (char c : s) {
        if (c == '1') {
            current_count++;
            max_consecutive_ones = max(max_consecutive_ones, current_count);
        } else {
            current_count = 0;
        }
    }

    return max_consecutive_ones;
}

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

    int t;
    cin >> t;

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

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

        int max_consecutive_ones = calculate_max_consecutive_ones(s, n);
        
        // Simulate Roy's and Emon's turns
        for (int i = 0; i < flip_indices.size(); ++i) {
            int flip_index = flip_indices[i];
            s[flip_index] = '1';

            max_consecutive_ones = max(max_consecutive_ones, calculate_max_consecutive_ones(s, n));
            
            // Flip back to the original to simulate Emon's turn
            s[flip_index] = '0';
        }

        cout << max_consecutive_ones << 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:44:58
Judged At
2024-11-06 14:44:58
Judged By
Score
0
Total Time
19ms
Peak Memory
576.0 KiB