/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 26ms 552.0 KiB
#3 Wrong Answer 7ms 320.0 KiB

Code

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

int main() {
    int T;
    cin >> T;
    
    while (T--) {
        int N;
        string S;
        cin >> N >> S;
        
        // Step 1: Count consecutive 1's blocks in the initial string
        vector<int> onesBlocks;
        int count = 0;
        
        // Counting blocks of consecutive 1's
        for (int i = 0; i < N; ++i) {
            if (S[i] == '1') {
                count++;
            } else {
                if (count > 0) {
                    onesBlocks.push_back(count);
                }
                count = 0;
            }
        }
        if (count > 0) {
            onesBlocks.push_back(count); // For trailing 1's
        }

        // If there are no blocks of 1's at all
        if (onesBlocks.empty()) {
            cout << 0 << endl;
            continue;
        }

        // Step 2: Strategy Simulation
        // Roy's aim: Maximize consecutive 1's
        // Emon's aim: Minimize consecutive 1's

        // We know that Emon can break any large block of 1's
        // The longest block at the end could be at most 1 (since players flip optimally)

        // Find the largest block of consecutive 1's initially
        int maxConsecutiveOnes = *max_element(onesBlocks.begin(), onesBlocks.end());

        // In most cases, the result is either the largest block or 1 (since Emon will break large blocks)
        cout << min(maxConsecutiveOnes, 1) << 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:59:39
Judged At
2024-11-11 02:24:53
Judged By
Score
5
Total Time
26ms
Peak Memory
552.0 KiB