# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
924722 |
2024-02-09T14:53:44 Z |
a_l_i_r_e_z_a |
Toll (BOI17_toll) |
C++17 |
|
116 ms |
266596 KB |
// In the name of God
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
const int maxn = 4e5, lg = 17;
const int inf = 1e9 + 7, mod = 1e9 + 7;
int k, n, m, q;
struct D{
int node[5];
D(){
for(int i = 0; i < 5; i++) node[i] = inf;
}
} dp[maxn][lg];
D merge(D a, int u, int b){
for(int i = 0; i < k; i++){
int x = inf;
for(int j = 0; j < k; j++) smin(x, a.node[j] + dp[u * k + j][b].node[i]);
a.node[i] = x;
}
return a;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> k >> n >> m >> q;
for(int i = 0; i < m; i++){
int u, v, w; cin >> u >> v >> w;
dp[u][0].node[v % k] = w;
}
for(int i = n - 1; i >= 0; i--){
for(int j = 1; j < lg; j++){
dp[i][j] = merge(dp[i][j - 1], (i / k) + (1ll << (j - 1)), j - 1);
}
}
while(q--){
int u, v; cin >> u >> v;
if(u / k >= v / k){
cout << -1 << '\n';
continue;
}
int x = u / k + 1, y = v / k;
D ans = dp[u][0];
for(int i = 0; i < lg; i++){
if((y - x) & (1ll << i)){
ans = merge(ans, x, i);
x += 1ll << i;
}
}
if(ans.node[v % k] >= inf) cout << -1 << '\n';
else cout << ans.node[v % k] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
266480 KB |
Output is correct |
2 |
Correct |
53 ms |
266504 KB |
Output is correct |
3 |
Correct |
50 ms |
266596 KB |
Output is correct |
4 |
Correct |
51 ms |
266580 KB |
Output is correct |
5 |
Correct |
52 ms |
266444 KB |
Output is correct |
6 |
Correct |
52 ms |
266580 KB |
Output is correct |
7 |
Correct |
52 ms |
266580 KB |
Output is correct |
8 |
Correct |
99 ms |
266572 KB |
Output is correct |
9 |
Correct |
90 ms |
266576 KB |
Output is correct |
10 |
Correct |
77 ms |
266572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
110 ms |
266576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
266460 KB |
Output is correct |
2 |
Incorrect |
50 ms |
266328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
266460 KB |
Output is correct |
2 |
Incorrect |
50 ms |
266328 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
266480 KB |
Output is correct |
2 |
Correct |
53 ms |
266504 KB |
Output is correct |
3 |
Correct |
50 ms |
266596 KB |
Output is correct |
4 |
Correct |
51 ms |
266580 KB |
Output is correct |
5 |
Correct |
52 ms |
266444 KB |
Output is correct |
6 |
Correct |
52 ms |
266580 KB |
Output is correct |
7 |
Correct |
52 ms |
266580 KB |
Output is correct |
8 |
Correct |
99 ms |
266572 KB |
Output is correct |
9 |
Correct |
90 ms |
266576 KB |
Output is correct |
10 |
Correct |
77 ms |
266572 KB |
Output is correct |
11 |
Incorrect |
110 ms |
266576 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |