QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#781105 | #4935. Exchange Bottleneck | std_abs# | WA | 3ms | 3852kb | C++20 | 852b | 2024-11-25 14:48:46 | 2024-11-25 14:48:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 998244353, N = 100007;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n, --n;
vector <int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int ans = 1;
vector <int> lst(n, -1);
for (int i = n - 1; ~i; --i) {
if (i + 1 < n) {
lst[i] = lst[i + 1];
}
if (a[i] == 1) {
lst[i] = i;
}
}
int prev = -1;
for (int i = 0; i < n; ++i) {
if (a[i] == 0) {
int closet = i + 1;
if (prev != -1) closet = min(closet, i - prev + 1);
if (lst[i] != -1) closet = min(closet, lst[i] - i + 1);
ans = max(ans, closet);
} else {
prev = i;
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
5 1 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
7 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
2 0
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 3848kb
input:
90580 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 ...
output:
3
result:
wrong answer 1st lines differ - expected: '2', found: '3'