QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133431#4935. Exchange BottleneckVengeful_Spirit#RE 1ms5508kbC++20646b2023-08-02 09:24:492023-08-02 09:24:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 09:24:53]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5508kb
  • [2023-08-02 09:24:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], pr[N], sf[N];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i < n; ++i) {
        cin >> a[i];
        pr[i] = pr[i - 1];
        if(a[i] == 1) pr[i] = i;
    }
    sf[n + 1] = 1e9;
    for(int i = n; i >= 1; --i) {
        if(a[i] == 1) sf[i] = i;
        else sf[i] = sf[i + 1];
    }
    int ans = 0;
    assert(a[1]);
    for(int i = 1; i < n; ++i) {
        int pos = min(i - pr[i] + 1, sf[i] - i + 1);
        // cerr << i << " " << pos << "\n";
        ans = max(ans, pos);
    }
    cout << ans << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5380kb

input:

5
1 0 1 0

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5508kb

input:

7
1 1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Dangerous Syscalls

input:

2
0

output:


result: