Accepted
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-11 02:32:38
- Judged By
- Score
- 100
- Total Time
- 6ms
- Peak Memory
- 1000.0 KiB