QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329249 | #4935. Exchange Bottleneck | ouo# | TL | 2ms | 3708kb | C++20 | 1.2kb | 2024-02-16 15:03:23 | 2024-02-16 15:03:24 |
Judging History
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) {
dp[now.S] = now.F;
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: 2ms
memory: 3604kb
input:
5 1 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
7 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3708kb
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 ...