# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439947 |
2021-07-01T09:27:08 Z |
K4YAN |
Toll (BOI17_toll) |
C++17 |
|
158 ms |
20948 KB |
//Be Name Khoda
// 16:25 | 13:30
#include<bits/stdc++.h>
#pragma GCC optimize ("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define pii pair<int, int>
#define plll pair<pll, ll>
#define piii pair<pii, int>
#define piiii pair<pii, pii>
const int mxn = 5e4 + 5;
int n, m, k, o;
int dis[mxn][18][5], arr[5][2];
vector<pii> adj[mxn], Qu;
void input() {
for(int i = 0; i < mxn; i++) {
for(int j = 0; j < 18; j++) {
for(int e = 0; e < 5; e++) {
dis[i][j][e] = 1e9;
}
}
}
cin >> k >> n >> m >> o;
int v, u, w;
for(int i = 0; i < m; i++) {
cin >> v >> u >> w;
adj[v].push_back({u, w});
dis[v][0][u % k] = w;
}
for(int i = 0; i < o; i++) {
cin >> v >> u;
if(v / k == u / k) {
Qu.push_back({-1, -1});
continue;
}
if(v > u) {
Qu.push_back({-1, -1});
continue;
}
Qu.push_back({v, u});
}
}
void solve() {
for(int i = 1; i < 18; i++) {
for(int j = 0; j < n; j++) {
for(int w = 0; w < k; w++) {
for(int q = 0; q < k; q++) {
int t = j + (k * (1 << (i - 1))) - (j % k) + q;
if(t > n) {
break;
}
dis[j][i][w] = min(dis[j][i][w], dis[j][i - 1][q] + dis[j + (k * (1 << (i - 1))) - (j % k) + q][i - 1][w]);
}
}
}
}
int x, gn;
vector<int> v;
for(auto Q : Qu) {
if(Q.first == -1) {
cout << "-1" << endl;
continue;
}
for(int i = 0; i < k; i++) {
arr[i][0] = 1e9;
arr[i][1] = 1e9;
}
for(auto g : adj[Q.first]) {
arr[g.first % k][0] = g.second;
v.push_back(g.first);
}
gn = Q.first / k + 1;
x = (Q.second / k) - (Q.first / k) - 1;
for(int i = 17; i > -1; i--) {
if(x - (1 << i) >= 0) {
x -= (1 << i);
gn += (1 << i);
for(int j = 0; j < k; j++) {
for(auto g : v) {
arr[j][1] = min(arr[j][1], arr[g % k][0] + dis[g][i][j]);
}
}
v.clear();
for(int j = 0; j < k; j++) {
arr[j][0] = arr[j][1];
arr[j][1] = 1e9;
if(arr[j][0] < 1e9) {
v.push_back(k * gn + j);
}
}
}
}
if(arr[Q.second % k][0] >= 1e9) {
arr[Q.second % k][0] = -1;
}
cout << arr[Q.second % k][0] << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
input(), solve();
return 0;
}
/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
20948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
158 ms |
20844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
19020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
19020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
20948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |