QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#329170 | #4935. Exchange Bottleneck | ouo# | TL | 3ms | 31024kb | C++17 | 1.2kb | 2024-02-16 14:22:51 | 2024-02-16 14:22:52 |
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) {
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;
}
詳細信息
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 ...