QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116594 | #6564. Frequent Flier | NYCU_Yamada# | AC ✓ | 503ms | 29424kb | C++20 | 2.1kb | 2023-06-29 16:11:52 | 2023-06-29 16:11:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int maxn = 2e5 + 87;
int f[maxn] = {}, dis[maxn] = {};
vector<pair<int, int>> G[maxn];
int n, m, k;
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) {
cin >> f[i];
}
for(int i = 1; i <= n; ++i) {
f[i] += f[i - 1];
}
for(int i = 1; i <= n; ++i) {
G[i].emplace_back(i - 1, f[i] - f[i - 1]); // s[i] - s[i - 1] <= f[i]
G[i - 1].emplace_back(i, 0); // s[i] - s[i - 1] >= 0
}
for(int i = 1; i <= n; ++i) {
int p = max(i - m, int(0));
int d = min(k, f[i] - f[p]);
G[p].emplace_back(i, -d); // s[i] - s[p] >= d
}
for(int i = 1; i < m; ++i) {
int p = max(n - m + i, int(0));
int d = min(k, f[n] - f[p]);
G[p].emplace_back(n, -d); // s[n] - s[p] >= d
}
// min distance
// priority_queue<pair<int, int>> pq;
// memset(dis, 0x3f, sizeof(dis));
// dis[0] = 0;
// pq.emplace(dis[0], 0);
// while(pq.size()) {
// int x = pq.top().second;
// int d = -pq.top().first;
// pq.pop();
// if(dis[x] != d) continue;
// for(auto e : G[x]) {
// if(dis[e.first] > dis[x] + e.second) {
// dis[e.first] = dis[x] + e.second;
// pq.emplace(-dis[e.first], e.first);
// }
// }
// }
queue<int> que;
vector<bool> inq(n + 1);
memset(dis, 0x3f, sizeof(dis));
dis[0] = 0; inq[0] = 1; que.emplace(0);
while(que.size()) {
int x = que.front();
inq[x] = 0;
que.pop();
for(auto e : G[x]) {
if(dis[e.first] > dis[x] + e.second) {
dis[e.first] = dis[x] + e.second;
if(!inq[e.first]) {
que.emplace(e.first);
inq[e.first] = 1;
}
}
}
}
cout << -dis[n] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 10456kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 32ms
memory: 26944kb
input:
200000 2467 999931035 182548858 69876218 33328350 919486767 739850600 948199964 392292320 39077742 366752074 917496841 246661698 37219034 56677740 188278971 965701828 28059790 13200243 825730775 542597589 320715170 939054378 470563899 914247467 990100491 290827128 903662394 611104879 18631185 412134...
output:
82994275905
result:
ok single line: '82994275905'
Test #3:
score: 0
Accepted
time: 6ms
memory: 16856kb
input:
1 200000 999959273 1255319
output:
1255319
result:
ok single line: '1255319'
Test #4:
score: 0
Accepted
time: 23ms
memory: 29424kb
input:
200000 118880 996878327 993340390 999483057 808153702 337349872 863222189 7495963 995920883 12950768 958082368 993215196 967152406 1388062 949959944 836952150 964071667 5291 139115263 958470154 51295691 175385 925242139 995685554 10895812 12563 55482 479983443 42805 996241239 6228013 302633329 10331...
output:
2990634981
result:
ok single line: '2990634981'
Test #5:
score: 0
Accepted
time: 503ms
memory: 26968kb
input:
200000 15 44049967 999927791 29351 999894087 687373343 518282902 19725626 452930 6701 999697321 27032796 5498 259987 999999980 485673990 805879 315651507 166801295 189865616 999910671 6203805 978801777 41916529 942904087 997589912 17146790 922137016 444882952 999884603 999926345 938979650 18597283 9...
output:
598769574112
result:
ok single line: '598769574112'