# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
536480 |
2022-03-13T11:58:05 Z |
cig32 |
Toll (BOI17_toll) |
C++17 |
|
3000 ms |
8400 KB |
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 120717661;
#define int long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
if(p==0) return 1 % MOD;
long long r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
long long inv(long long b) {
return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) {
long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() {
for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
void solve(int tc) {
int k, n, m, q;
cin >> k >> n >> m >> q;
if(k == 1) {
int ps[n];
for(int i=0; i<n; i++) ps[i] = -1e13;
for(int i=1; i<=m; i++) {
int a, b, t;
cin >> a >> b >> t;
ps[a] = t;
}
for(int i=1; i<n; i++) ps[i] += ps[i-1];
for(int i=0; i<q; i++) {
int a, b;
cin >> a >> b;
int p = ps[b - 1] - (a == 0 ? 0 : ps[a - 1]);
if(p < 0) cout << "-1\n";
else cout << p << "\n";
}
return;
}
vector<pair<int, int> > from[n];
for(int i=0; i<m; i++) {
int a, b, t;
cin >> a >> b >> t;
from[b].push_back({a, t});
}
for(int i=0; i<q; i++) {
int a, b;
cin >> a >> b;
int dist[2*k];
for(int j=0; j<2*k; j++) dist[j] = 1e18;
dist[a % (2*k)] = 0;
for(int j=a+1; j<=b; j++) {
int wow = 1e18;
for(auto x: from[j]) {
wow = min(wow, dist[x.first % (2*k)] + x.second);
}
dist[j % (2*k)] = wow;
}
cout << (dist[b % (2*k)] == 1e18 ? -1 : dist[b % (2*k)]) << '\n';
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
724 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
14 ms |
744 KB |
Output is correct |
9 |
Correct |
12 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3096 ms |
4036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
412 KB |
Output is correct |
10 |
Correct |
12 ms |
1468 KB |
Output is correct |
11 |
Correct |
69 ms |
5528 KB |
Output is correct |
12 |
Correct |
87 ms |
7580 KB |
Output is correct |
13 |
Correct |
100 ms |
8208 KB |
Output is correct |
14 |
Correct |
82 ms |
6360 KB |
Output is correct |
15 |
Correct |
53 ms |
4204 KB |
Output is correct |
16 |
Correct |
49 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
412 KB |
Output is correct |
10 |
Correct |
12 ms |
1468 KB |
Output is correct |
11 |
Correct |
69 ms |
5528 KB |
Output is correct |
12 |
Correct |
87 ms |
7580 KB |
Output is correct |
13 |
Correct |
100 ms |
8208 KB |
Output is correct |
14 |
Correct |
82 ms |
6360 KB |
Output is correct |
15 |
Correct |
53 ms |
4204 KB |
Output is correct |
16 |
Correct |
49 ms |
4204 KB |
Output is correct |
17 |
Correct |
1020 ms |
5596 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
19 ms |
472 KB |
Output is correct |
25 |
Correct |
31 ms |
536 KB |
Output is correct |
26 |
Correct |
27 ms |
468 KB |
Output is correct |
27 |
Correct |
12 ms |
1468 KB |
Output is correct |
28 |
Correct |
1368 ms |
7628 KB |
Output is correct |
29 |
Correct |
1448 ms |
8400 KB |
Output is correct |
30 |
Correct |
1261 ms |
6628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
724 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
14 ms |
744 KB |
Output is correct |
9 |
Correct |
12 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Execution timed out |
3096 ms |
4036 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |