/**********************GOD**********************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <map>
using namespace std;
#pragma GCC Optimize("O3, Unroll-loops");
typedef long long ll;
typedef long double ld;
typedef pair<ll , ll> pll;
#define len length()
#define MP make_pair
#define fs first
#define sc second
#define pb push_back
#define all(x) x.begin() , x.end()
#define kill(x) cout << x , exit(0)
const int INF = 1e9 + 7;
const int MXN = 5e4 + 4;
int n, m, k;
int q;
vector<pair<int, int>> Q[MXN];
int adj[MXN][13];
int dist[MXN], ans[MXN];
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> k >> n >> m >> q;
for(int i = 0; i < n; i ++)
for(int j = 0; j < 13; j ++)
adj[i][j] = INF;
for(int i = 0; i < m; i ++) {
int v, u, w; cin >> v >> u >> w;
adj[u][u - v] = w;
}
for(int i = 0; i < q; i ++) {
int v, u; cin >> v >> u;
Q[v].pb({u, i});
}
for(int v = 0; v < n; v ++) {
if(Q[v].empty())
continue;
for(int u = 0; u < n; u ++)
dist[u] = INF;
dist[v] = 0;
for(int u = v + 1; u < n; u ++)
for(int i = 1; i < 2 * k; i ++)
if(u - i >= v)
dist[u] = min(dist[u], adj[u][i] + dist[u - i]);
else
break;
for(auto[u, i] : Q[v])
ans[i] = (dist[u] < INF ? dist[u] : -1);
}
for(int i = 0; i < q; i ++)
cout << ans[i] << '\n';
return 0;
}
/*!
ahkh
*/
Compilation message
toll.cpp:18: warning: ignoring '#pragma GCC Optimize' [-Wunknown-pragmas]
18 | #pragma GCC Optimize("O3, Unroll-loops");
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1186 ms |
5468 KB |
Output is correct |
2 |
Correct |
1 ms |
3672 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
3 ms |
3700 KB |
Output is correct |
6 |
Correct |
3 ms |
3676 KB |
Output is correct |
7 |
Correct |
3 ms |
3676 KB |
Output is correct |
8 |
Correct |
1173 ms |
5452 KB |
Output is correct |
9 |
Correct |
1170 ms |
5448 KB |
Output is correct |
10 |
Correct |
1155 ms |
4800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
5516 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3684 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
2 ms |
3684 KB |
Output is correct |
6 |
Correct |
1 ms |
3672 KB |
Output is correct |
7 |
Correct |
5 ms |
3932 KB |
Output is correct |
8 |
Correct |
4 ms |
3932 KB |
Output is correct |
9 |
Correct |
12 ms |
5420 KB |
Output is correct |
10 |
Correct |
29 ms |
5972 KB |
Output is correct |
11 |
Correct |
21 ms |
5724 KB |
Output is correct |
12 |
Correct |
21 ms |
5520 KB |
Output is correct |
13 |
Correct |
26 ms |
3688 KB |
Output is correct |
14 |
Correct |
22 ms |
3688 KB |
Output is correct |
15 |
Correct |
14 ms |
3676 KB |
Output is correct |
16 |
Correct |
17 ms |
3776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
1 ms |
3676 KB |
Output is correct |
6 |
Correct |
1 ms |
3672 KB |
Output is correct |
7 |
Correct |
2 ms |
3672 KB |
Output is correct |
8 |
Correct |
2 ms |
3676 KB |
Output is correct |
9 |
Correct |
2 ms |
3676 KB |
Output is correct |
10 |
Correct |
23 ms |
4188 KB |
Output is correct |
11 |
Correct |
41 ms |
4388 KB |
Output is correct |
12 |
Correct |
49 ms |
4384 KB |
Output is correct |
13 |
Correct |
61 ms |
4364 KB |
Output is correct |
14 |
Correct |
47 ms |
4188 KB |
Output is correct |
15 |
Correct |
50 ms |
3672 KB |
Output is correct |
16 |
Correct |
37 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3672 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
1 ms |
3676 KB |
Output is correct |
6 |
Correct |
1 ms |
3672 KB |
Output is correct |
7 |
Correct |
2 ms |
3672 KB |
Output is correct |
8 |
Correct |
2 ms |
3676 KB |
Output is correct |
9 |
Correct |
2 ms |
3676 KB |
Output is correct |
10 |
Correct |
23 ms |
4188 KB |
Output is correct |
11 |
Correct |
41 ms |
4388 KB |
Output is correct |
12 |
Correct |
49 ms |
4384 KB |
Output is correct |
13 |
Correct |
61 ms |
4364 KB |
Output is correct |
14 |
Correct |
47 ms |
4188 KB |
Output is correct |
15 |
Correct |
50 ms |
3672 KB |
Output is correct |
16 |
Correct |
37 ms |
3676 KB |
Output is correct |
17 |
Correct |
609 ms |
4468 KB |
Output is correct |
18 |
Correct |
1 ms |
3672 KB |
Output is correct |
19 |
Correct |
1 ms |
3672 KB |
Output is correct |
20 |
Correct |
1 ms |
3676 KB |
Output is correct |
21 |
Correct |
1 ms |
3676 KB |
Output is correct |
22 |
Correct |
1 ms |
3676 KB |
Output is correct |
23 |
Correct |
4 ms |
3672 KB |
Output is correct |
24 |
Correct |
5 ms |
3676 KB |
Output is correct |
25 |
Correct |
8 ms |
3756 KB |
Output is correct |
26 |
Correct |
7 ms |
3676 KB |
Output is correct |
27 |
Correct |
388 ms |
4472 KB |
Output is correct |
28 |
Correct |
805 ms |
4460 KB |
Output is correct |
29 |
Correct |
814 ms |
4676 KB |
Output is correct |
30 |
Correct |
833 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1186 ms |
5468 KB |
Output is correct |
2 |
Correct |
1 ms |
3672 KB |
Output is correct |
3 |
Correct |
1 ms |
3676 KB |
Output is correct |
4 |
Correct |
1 ms |
3676 KB |
Output is correct |
5 |
Correct |
3 ms |
3700 KB |
Output is correct |
6 |
Correct |
3 ms |
3676 KB |
Output is correct |
7 |
Correct |
3 ms |
3676 KB |
Output is correct |
8 |
Correct |
1173 ms |
5452 KB |
Output is correct |
9 |
Correct |
1170 ms |
5448 KB |
Output is correct |
10 |
Correct |
1155 ms |
4800 KB |
Output is correct |
11 |
Correct |
24 ms |
5516 KB |
Output is correct |
12 |
Correct |
1 ms |
3676 KB |
Output is correct |
13 |
Correct |
1 ms |
3684 KB |
Output is correct |
14 |
Correct |
1 ms |
3676 KB |
Output is correct |
15 |
Correct |
2 ms |
3684 KB |
Output is correct |
16 |
Correct |
1 ms |
3672 KB |
Output is correct |
17 |
Correct |
5 ms |
3932 KB |
Output is correct |
18 |
Correct |
4 ms |
3932 KB |
Output is correct |
19 |
Correct |
12 ms |
5420 KB |
Output is correct |
20 |
Correct |
29 ms |
5972 KB |
Output is correct |
21 |
Correct |
21 ms |
5724 KB |
Output is correct |
22 |
Correct |
21 ms |
5520 KB |
Output is correct |
23 |
Correct |
26 ms |
3688 KB |
Output is correct |
24 |
Correct |
22 ms |
3688 KB |
Output is correct |
25 |
Correct |
14 ms |
3676 KB |
Output is correct |
26 |
Correct |
17 ms |
3776 KB |
Output is correct |
27 |
Correct |
1 ms |
3672 KB |
Output is correct |
28 |
Correct |
1 ms |
3676 KB |
Output is correct |
29 |
Correct |
1 ms |
3676 KB |
Output is correct |
30 |
Correct |
1 ms |
3676 KB |
Output is correct |
31 |
Correct |
1 ms |
3676 KB |
Output is correct |
32 |
Correct |
1 ms |
3672 KB |
Output is correct |
33 |
Correct |
2 ms |
3672 KB |
Output is correct |
34 |
Correct |
2 ms |
3676 KB |
Output is correct |
35 |
Correct |
2 ms |
3676 KB |
Output is correct |
36 |
Correct |
23 ms |
4188 KB |
Output is correct |
37 |
Correct |
41 ms |
4388 KB |
Output is correct |
38 |
Correct |
49 ms |
4384 KB |
Output is correct |
39 |
Correct |
61 ms |
4364 KB |
Output is correct |
40 |
Correct |
47 ms |
4188 KB |
Output is correct |
41 |
Correct |
50 ms |
3672 KB |
Output is correct |
42 |
Correct |
37 ms |
3676 KB |
Output is correct |
43 |
Correct |
609 ms |
4468 KB |
Output is correct |
44 |
Correct |
1 ms |
3672 KB |
Output is correct |
45 |
Correct |
1 ms |
3672 KB |
Output is correct |
46 |
Correct |
1 ms |
3676 KB |
Output is correct |
47 |
Correct |
1 ms |
3676 KB |
Output is correct |
48 |
Correct |
1 ms |
3676 KB |
Output is correct |
49 |
Correct |
4 ms |
3672 KB |
Output is correct |
50 |
Correct |
5 ms |
3676 KB |
Output is correct |
51 |
Correct |
8 ms |
3756 KB |
Output is correct |
52 |
Correct |
7 ms |
3676 KB |
Output is correct |
53 |
Correct |
388 ms |
4472 KB |
Output is correct |
54 |
Correct |
805 ms |
4460 KB |
Output is correct |
55 |
Correct |
814 ms |
4676 KB |
Output is correct |
56 |
Correct |
833 ms |
4472 KB |
Output is correct |
57 |
Execution timed out |
3008 ms |
4684 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |