# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1083141 |
2024-09-02T16:36:08 Z |
_8_8_ |
Toll (BOI17_toll) |
C++17 |
|
2861 ms |
524288 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 12, MOD = (int)1e9 + 7;
int k, n, m, q, b;
vector<pair<int,int>> g[N], o;
vector<ll> di[N];
const int inf = 1e9 + 1;
vector<ll> tr(vector<ll> prev,int l, int r) {
vector<ll> ret(k,inf);
assert(l % k == 0);
for(int i = l; i <= r; i++) {
int f = i % k;
for(auto [to,w]:g[i]) {
ret[to % k] = min(ret[to % k],prev[f] + w);
}
}
return ret;
}
void prec() {
for(int i = (int)o.size() - 1; i >= 0; i--) {
if(i % b == 0) {
int nx = i + b;
int l = o[i].first, r = o[i].second;
for(int j = l; j <= r; j++) {
vector<ll> dd(k,inf);
dd[j%k] = 0;
for(int _i = i + 1; _i < (int)o.size(); _i++) {
vector<ll> nv = tr(dd,o[_i - 1].first,o[_i - 1].second);
for(auto f:nv) {
di[j].push_back(f);
}
dd = nv;
}
}
}
}
}
void test() {
cin >> k >> n >> m >> q;
for(int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
g[a].push_back({b,c});
}
for(int i = 0; i <= n; i++) {
int l = i * k, r = (i + 1) * k - 1;
if(l >= n) break;
if(r >= n) {
r = n - 1;
}
o.push_back({l,r});
}
for(int i = 0; i < n; i++) {
sort(g[i].begin(),g[i].end());
vector<pair<int,int>> nv;
for(auto [x,y]:g[i]) {
if(nv.empty() || nv.back().first != x) {
nv.emplace_back(x,y);
}
}
g[i].swap(nv);
assert((int)g[i].size() <= k);
}
// b = sqrtl(n * 1ll * n / q);
b = 1;
prec();
// return;
while(q--) {
int a, b;
cin >> a >> b;
if(a / k >= b / k) {
cout << -1 << '\n';
continue;
}
int nx = a / k + 1, x = nx * k;
int ret = di[a][b - x];
if(ret == inf)
ret = -1;
cout << ret << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
Compilation message
toll.cpp: In function 'void prec()':
toll.cpp:26:17: warning: unused variable 'nx' [-Wunused-variable]
26 | int nx = i + b;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2852 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2245 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47196 KB |
Output is correct |
2 |
Correct |
18 ms |
47196 KB |
Output is correct |
3 |
Correct |
20 ms |
47420 KB |
Output is correct |
4 |
Correct |
19 ms |
47220 KB |
Output is correct |
5 |
Correct |
18 ms |
47392 KB |
Output is correct |
6 |
Correct |
44 ms |
52564 KB |
Output is correct |
7 |
Correct |
33 ms |
52504 KB |
Output is correct |
8 |
Correct |
32 ms |
52628 KB |
Output is correct |
9 |
Correct |
30 ms |
52540 KB |
Output is correct |
10 |
Runtime error |
2861 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
47196 KB |
Output is correct |
2 |
Correct |
18 ms |
47196 KB |
Output is correct |
3 |
Correct |
20 ms |
47420 KB |
Output is correct |
4 |
Correct |
19 ms |
47220 KB |
Output is correct |
5 |
Correct |
18 ms |
47392 KB |
Output is correct |
6 |
Correct |
44 ms |
52564 KB |
Output is correct |
7 |
Correct |
33 ms |
52504 KB |
Output is correct |
8 |
Correct |
32 ms |
52628 KB |
Output is correct |
9 |
Correct |
30 ms |
52540 KB |
Output is correct |
10 |
Runtime error |
2861 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2852 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |