# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
702487 |
2023-02-24T07:52:31 Z |
RandomLB |
Toll (BOI17_toll) |
C++17 |
|
205 ms |
12608 KB |
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back
#define siz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ms(x, a) memset(x, a, sizeof(x))
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values){
string delim = "";
cout << vars << " = ";
(...,(cout << delim << values, delim = ", "));
cout << endl;
}
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
//=================================
const int MAX = 5e4+5;
vector<pi> adj[MAX], radj[MAX];
int tl[MAX], tr[MAX], res[MAX], dis[5][MAX], k;
bool vis[MAX];
void solve(int l, int r, vector<int> vec){
if (l/k == r/k) return;
int m = (l+(r-l)/2)/k;
//deb(l, r, m);
for (int i = 0; i < k; i++){
for (int j = l; j <= r; j++){
dis[i][j] = INF;
vis[j] = false;
}
queue<int> q;
q.push(m*k+i); dis[i][m*k+i] = 0;
while (siz(q)){
int v = q.front(); q.pop();
for (auto[u, w]: radj[v]){
if (u < l) continue;
dis[i][u] = min(dis[i][u], dis[i][v]+w);
if (!vis[u]){ vis[u] = true; q.push(u); }
}
}
q.push((m+1)*k+i); dis[i][(m+1)*k+i] = 0;
while (siz(q)){
int v = q.front(); q.pop();
for (auto[u, w]: adj[v]){
if (u > r) continue;
dis[i][u] = min(dis[i][u], dis[i][v]+w);
if (!vis[u]){ vis[u] = true; q.push(u); }
}
}
}
//deb(dis[2][0], dis[2][12]);
vector<int> v1, v2;
for (int i: vec){
//deb(i, tl[i], tr[i]);
if (tl[i]/k <= m && tr[i]/k > m){
for (int a = 0; a < k; a++){
for (auto[b, w]: adj[m*k+a]){
res[i] = min(res[i], dis[a][tl[i]]+w+dis[b-(m+1)*k][tr[i]]);
}
}
} else if (tr[i]/k <= m) v1.pb(i); else v2.pb(i);
}
solve(l, (m+1)*k-1, v1); solve((m+1)*k, r, v2);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m, q; cin >> k >> n >> m >> q;
for (int i = 1; i <= m; i++){
int a, b, w; cin >> a >> b >> w;
adj[a].pb({b, w});
radj[b].pb({a, w});
}
vector<int> v;
for (int i = 1; i <= q; i++){
cin >> tl[i] >> tr[i];
v.pb(i);
}
ms(res, INF);
solve(0, n/k*k+k-1, v);
for (int i = 1; i <= q; i++) cout << (res[i] < INF? res[i] : -1) << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
6720 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2804 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2900 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
3 ms |
2900 KB |
Output is correct |
8 |
Correct |
48 ms |
6688 KB |
Output is correct |
9 |
Correct |
31 ms |
6476 KB |
Output is correct |
10 |
Correct |
9 ms |
3460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
8324 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2804 KB |
Output is correct |
4 |
Correct |
1 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2808 KB |
Output is correct |
6 |
Correct |
2 ms |
2900 KB |
Output is correct |
7 |
Correct |
4 ms |
3200 KB |
Output is correct |
8 |
Correct |
5 ms |
3284 KB |
Output is correct |
9 |
Correct |
39 ms |
7292 KB |
Output is correct |
10 |
Correct |
112 ms |
10904 KB |
Output is correct |
11 |
Correct |
80 ms |
8380 KB |
Output is correct |
12 |
Correct |
67 ms |
8084 KB |
Output is correct |
13 |
Correct |
127 ms |
11380 KB |
Output is correct |
14 |
Correct |
64 ms |
8056 KB |
Output is correct |
15 |
Correct |
78 ms |
7500 KB |
Output is correct |
16 |
Correct |
72 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2808 KB |
Output is correct |
4 |
Correct |
1 ms |
2900 KB |
Output is correct |
5 |
Correct |
2 ms |
2900 KB |
Output is correct |
6 |
Correct |
2 ms |
2948 KB |
Output is correct |
7 |
Correct |
3 ms |
2984 KB |
Output is correct |
8 |
Correct |
4 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3080 KB |
Output is correct |
10 |
Correct |
50 ms |
7020 KB |
Output is correct |
11 |
Correct |
67 ms |
7860 KB |
Output is correct |
12 |
Correct |
110 ms |
10508 KB |
Output is correct |
13 |
Correct |
113 ms |
11228 KB |
Output is correct |
14 |
Correct |
115 ms |
9396 KB |
Output is correct |
15 |
Correct |
81 ms |
7400 KB |
Output is correct |
16 |
Correct |
71 ms |
7300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2808 KB |
Output is correct |
4 |
Correct |
1 ms |
2900 KB |
Output is correct |
5 |
Correct |
2 ms |
2900 KB |
Output is correct |
6 |
Correct |
2 ms |
2948 KB |
Output is correct |
7 |
Correct |
3 ms |
2984 KB |
Output is correct |
8 |
Correct |
4 ms |
3156 KB |
Output is correct |
9 |
Correct |
3 ms |
3080 KB |
Output is correct |
10 |
Correct |
50 ms |
7020 KB |
Output is correct |
11 |
Correct |
67 ms |
7860 KB |
Output is correct |
12 |
Correct |
110 ms |
10508 KB |
Output is correct |
13 |
Correct |
113 ms |
11228 KB |
Output is correct |
14 |
Correct |
115 ms |
9396 KB |
Output is correct |
15 |
Correct |
81 ms |
7400 KB |
Output is correct |
16 |
Correct |
71 ms |
7300 KB |
Output is correct |
17 |
Correct |
75 ms |
8060 KB |
Output is correct |
18 |
Correct |
1 ms |
2772 KB |
Output is correct |
19 |
Correct |
1 ms |
2772 KB |
Output is correct |
20 |
Correct |
1 ms |
2772 KB |
Output is correct |
21 |
Correct |
2 ms |
2900 KB |
Output is correct |
22 |
Correct |
2 ms |
2900 KB |
Output is correct |
23 |
Correct |
3 ms |
3028 KB |
Output is correct |
24 |
Correct |
4 ms |
3024 KB |
Output is correct |
25 |
Correct |
5 ms |
3156 KB |
Output is correct |
26 |
Correct |
4 ms |
3156 KB |
Output is correct |
27 |
Correct |
40 ms |
7156 KB |
Output is correct |
28 |
Correct |
109 ms |
10704 KB |
Output is correct |
29 |
Correct |
123 ms |
11308 KB |
Output is correct |
30 |
Correct |
93 ms |
9516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
6720 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
2 ms |
2804 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2900 KB |
Output is correct |
6 |
Correct |
3 ms |
2944 KB |
Output is correct |
7 |
Correct |
3 ms |
2900 KB |
Output is correct |
8 |
Correct |
48 ms |
6688 KB |
Output is correct |
9 |
Correct |
31 ms |
6476 KB |
Output is correct |
10 |
Correct |
9 ms |
3460 KB |
Output is correct |
11 |
Correct |
90 ms |
8324 KB |
Output is correct |
12 |
Correct |
2 ms |
2772 KB |
Output is correct |
13 |
Correct |
2 ms |
2804 KB |
Output is correct |
14 |
Correct |
1 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2808 KB |
Output is correct |
16 |
Correct |
2 ms |
2900 KB |
Output is correct |
17 |
Correct |
4 ms |
3200 KB |
Output is correct |
18 |
Correct |
5 ms |
3284 KB |
Output is correct |
19 |
Correct |
39 ms |
7292 KB |
Output is correct |
20 |
Correct |
112 ms |
10904 KB |
Output is correct |
21 |
Correct |
80 ms |
8380 KB |
Output is correct |
22 |
Correct |
67 ms |
8084 KB |
Output is correct |
23 |
Correct |
127 ms |
11380 KB |
Output is correct |
24 |
Correct |
64 ms |
8056 KB |
Output is correct |
25 |
Correct |
78 ms |
7500 KB |
Output is correct |
26 |
Correct |
72 ms |
7372 KB |
Output is correct |
27 |
Correct |
2 ms |
2772 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2808 KB |
Output is correct |
30 |
Correct |
1 ms |
2900 KB |
Output is correct |
31 |
Correct |
2 ms |
2900 KB |
Output is correct |
32 |
Correct |
2 ms |
2948 KB |
Output is correct |
33 |
Correct |
3 ms |
2984 KB |
Output is correct |
34 |
Correct |
4 ms |
3156 KB |
Output is correct |
35 |
Correct |
3 ms |
3080 KB |
Output is correct |
36 |
Correct |
50 ms |
7020 KB |
Output is correct |
37 |
Correct |
67 ms |
7860 KB |
Output is correct |
38 |
Correct |
110 ms |
10508 KB |
Output is correct |
39 |
Correct |
113 ms |
11228 KB |
Output is correct |
40 |
Correct |
115 ms |
9396 KB |
Output is correct |
41 |
Correct |
81 ms |
7400 KB |
Output is correct |
42 |
Correct |
71 ms |
7300 KB |
Output is correct |
43 |
Correct |
75 ms |
8060 KB |
Output is correct |
44 |
Correct |
1 ms |
2772 KB |
Output is correct |
45 |
Correct |
1 ms |
2772 KB |
Output is correct |
46 |
Correct |
1 ms |
2772 KB |
Output is correct |
47 |
Correct |
2 ms |
2900 KB |
Output is correct |
48 |
Correct |
2 ms |
2900 KB |
Output is correct |
49 |
Correct |
3 ms |
3028 KB |
Output is correct |
50 |
Correct |
4 ms |
3024 KB |
Output is correct |
51 |
Correct |
5 ms |
3156 KB |
Output is correct |
52 |
Correct |
4 ms |
3156 KB |
Output is correct |
53 |
Correct |
40 ms |
7156 KB |
Output is correct |
54 |
Correct |
109 ms |
10704 KB |
Output is correct |
55 |
Correct |
123 ms |
11308 KB |
Output is correct |
56 |
Correct |
93 ms |
9516 KB |
Output is correct |
57 |
Correct |
205 ms |
12608 KB |
Output is correct |
58 |
Correct |
40 ms |
7368 KB |
Output is correct |
59 |
Correct |
85 ms |
8584 KB |
Output is correct |