/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 25ms 532.0 KiB
#3 Wrong Answer 6ms 532.0 KiB

Code

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

using namespace std;

int main() {
    int T;
    cin >> T;
    
    while (T--) {
        int N;
        cin >> N;
        string S;
        cin >> S;
        
        // Create an array to count consecutive 1's blocks.
        vector<int> onesBlocks;
        int count = 0;
        
        // Group consecutive 1's together
        for (int i = 0; i < N; ++i) {
            if (S[i] == '1') {
                count++;
            } else {
                if (count > 0) {
                    onesBlocks.push_back(count);
                }
                count = 0;
            }
        }
        
        // If there's a trailing sequence of 1's, add it as well
        if (count > 0) {
            onesBlocks.push_back(count);
        }
        
        // The number of blocks of consecutive ones
        int blocksCount = onesBlocks.size();
        
        // Since Roy starts first, he will aim to increase the largest block of consecutive 1's.
        // Emon will aim to decrease the length of the largest block.
        
        // In the worst case scenario, if Emon is able to break the blocks optimally, he will reduce the largest block of consecutive 1's to 1.
        
        if (blocksCount == 0) {
            // No ones, the answer is 0
            cout << 0 << endl;
        } else {
            // If there are blocks of consecutive 1's, we can reduce them to a maximum of 1
            int maxConsecutiveOnes = *max_element(onesBlocks.begin(), onesBlocks.end());
            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:54:58
Judged At
2024-11-06 14:54:58
Judged By
Score
5
Total Time
25ms
Peak Memory
532.0 KiB