/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 8ms 568.0 KiB
#3 Accepted 4ms 540.0 KiB
#4 Accepted 4ms 592.0 KiB
#5 Accepted 4ms 652.0 KiB
#6 Accepted 4ms 832.0 KiB
#7 Accepted 4ms 1.105 MiB
#8 Accepted 4ms 996.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'

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

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        deque<int> v;
        string s;
        cin >> s;
        if (s == "1")
        {
            cout << "0\n";
            continue;
        }
        if (s == "0")
        {
            cout << 1 << '\n';
            continue;
        }
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
                v.push_back(i);
        }
        int mx = 0;
        for (int i = 0; i < n; i++)
        {
            if (!v.size())
                mx = max(mx, n - i);
            else
            {
                if (s[i] == '0')
                {
                    mx = max(mx, v.front() - i);
                }
                else
                {
                    v.pop_front();
                }
            }
        }
        cout << mx << '\n';
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1113 Fliping Game
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 14:45:04
Judged At
2024-11-05 14:45:04
Judged By
Score
100
Total Time
8ms
Peak Memory
1.105 MiB