QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329170#4935. Exchange Bottleneckouo#TL 3ms31024kbC++171.2kb2024-02-16 14:22:512024-02-16 14:22:52

Judging History

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

  • [2024-02-16 14:22:52]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:31024kb
  • [2024-02-16 14:22:51]
  • 提交

answer

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;

int n;
int arr[1000005];
int dp[1000005];
vector<int> gh[1000005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
int ans;

void bfs() {
    fill(dp+2, dp+n+1, 1e9);
    pq.push(make_pair(dp[1], 1));
    while (!pq.empty()) {
        pair<int, int> now = pq.top();
        pq.pop();
        if (dp[now.S] != now.F) {
            continue;
        }
        for (auto next : gh[now.S]) {
            if (dp[next] > now.F + 1) {
                dp[next] = now.F + 1;
                pq.push(make_pair(dp[next], next));
            }
        }
    }
    for (int i = 1; i < n+1; i++) {
        ans = max(ans, dp[i]);
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> arr[i];
        if (arr[i]) {
            for (int j = i; j > 0; j--) {
                gh[i+1].push_back(j);
                gh[j].push_back(i+1);
            }
        }else {
            gh[i].push_back(i+1);
            gh[i+1].push_back(i);
        }
    }
    bfs();
    cout << ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 31024kb

input:

5
1 0 1 0

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 29836kb

input:

7
1 1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 27112kb

input:

2
0

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Time Limit Exceeded

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:


result: