Submission #328897

# Submission time Handle Problem Language Result Execution time Memory
328897 2020-11-18T12:04:43 Z syy Toll (BOI17_toll) C++17
100 / 100
153 ms 173420 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e11
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll k, n, m, q, a, b, c, dist[50005][17][5][5], p[50005][17];

int main() {
	fastio; cin >> k >> n >> m >> q;
	n += k - (n % k);
	FOR(i, 0, n/k-1) FOR(t, 0, 16) FOR(j, 0, k-1) FOR(l, 0, k-1) dist[i][t][j][l] = LLINF;
	memset(p, -1, sizeof p);
	FOR(i, 1, m) {
		cin >> a >> b >> c;
		dist[a/k][0][a%k][b%k] = c;
	}
	FOR(i, 0, n/k-2) p[i][0] = i+1;
	FOR(t, 1, 16) DEC(i, n/k-2, 0) if (p[i][t-1] != -1) p[i][t] = p[p[i][t-1]][t-1];
	DEC(i, n/k-1, 0) FOR(t, 1, 16) if (p[i][t] != -1) {
		FOR(x, 0, k-1) FOR(z, 0, k-1) FOR(y, 0, k-1) dist[i][t][x][z] = min(dist[i][t][x][z], dist[i][t-1][x][y] + dist[p[i][t-1]][t-1][y][z]);
	}
	while (q--) {
		cin >> a >> b;
		ll x = a/k;
		vi pos; FOR(i, 0, k-1) pos.pb((i == a%k ? 0 : LLINF));
		DEC(t, 16, 0) if (p[x][t] != -1 and p[x][t] <= b/k) {
			vi newpos(k, LLINF);
			FOR(i, 0, k-1) FOR(y, 0, k-1) newpos[y] = min(newpos[y], dist[x][t][i][y] + pos[i]);
			pos = newpos;
			x = p[x][t];
		}
		cout << (pos[b%k] == LLINF ? -1 : pos[b%k]) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 153 ms 173420 KB Output is correct
2 Correct 4 ms 7020 KB Output is correct
3 Correct 4 ms 7020 KB Output is correct
4 Correct 4 ms 7020 KB Output is correct
5 Correct 7 ms 10348 KB Output is correct
6 Correct 7 ms 10348 KB Output is correct
7 Correct 6 ms 10348 KB Output is correct
8 Correct 145 ms 173420 KB Output is correct
9 Correct 148 ms 173420 KB Output is correct
10 Correct 123 ms 173420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 90492 KB Output is correct
2 Correct 4 ms 7020 KB Output is correct
3 Correct 4 ms 7020 KB Output is correct
4 Correct 4 ms 7020 KB Output is correct
5 Correct 4 ms 7020 KB Output is correct
6 Correct 4 ms 7020 KB Output is correct
7 Correct 11 ms 10476 KB Output is correct
8 Correct 11 ms 8684 KB Output is correct
9 Correct 132 ms 173420 KB Output is correct
10 Correct 109 ms 62572 KB Output is correct
11 Correct 115 ms 90220 KB Output is correct
12 Correct 89 ms 62444 KB Output is correct
13 Correct 80 ms 26988 KB Output is correct
14 Correct 63 ms 40300 KB Output is correct
15 Correct 59 ms 26988 KB Output is correct
16 Correct 56 ms 26988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7020 KB Output is correct
2 Correct 4 ms 7020 KB Output is correct
3 Correct 4 ms 7020 KB Output is correct
4 Correct 4 ms 7020 KB Output is correct
5 Correct 5 ms 7020 KB Output is correct
6 Correct 8 ms 10348 KB Output is correct
7 Correct 5 ms 8684 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 5 ms 7788 KB Output is correct
10 Correct 122 ms 173420 KB Output is correct
11 Correct 109 ms 90220 KB Output is correct
12 Correct 99 ms 62500 KB Output is correct
13 Correct 104 ms 62572 KB Output is correct
14 Correct 90 ms 62572 KB Output is correct
15 Correct 55 ms 27116 KB Output is correct
16 Correct 54 ms 26988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7020 KB Output is correct
2 Correct 4 ms 7020 KB Output is correct
3 Correct 4 ms 7020 KB Output is correct
4 Correct 4 ms 7020 KB Output is correct
5 Correct 5 ms 7020 KB Output is correct
6 Correct 8 ms 10348 KB Output is correct
7 Correct 5 ms 8684 KB Output is correct
8 Correct 6 ms 7660 KB Output is correct
9 Correct 5 ms 7788 KB Output is correct
10 Correct 122 ms 173420 KB Output is correct
11 Correct 109 ms 90220 KB Output is correct
12 Correct 99 ms 62500 KB Output is correct
13 Correct 104 ms 62572 KB Output is correct
14 Correct 90 ms 62572 KB Output is correct
15 Correct 55 ms 27116 KB Output is correct
16 Correct 54 ms 26988 KB Output is correct
17 Correct 106 ms 90240 KB Output is correct
18 Correct 4 ms 7020 KB Output is correct
19 Correct 4 ms 7020 KB Output is correct
20 Correct 4 ms 7020 KB Output is correct
21 Correct 4 ms 7020 KB Output is correct
22 Correct 4 ms 7020 KB Output is correct
23 Correct 8 ms 10348 KB Output is correct
24 Correct 7 ms 8684 KB Output is correct
25 Correct 8 ms 7808 KB Output is correct
26 Correct 8 ms 7916 KB Output is correct
27 Correct 130 ms 173420 KB Output is correct
28 Correct 108 ms 62444 KB Output is correct
29 Correct 111 ms 62444 KB Output is correct
30 Correct 102 ms 62444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 173420 KB Output is correct
2 Correct 4 ms 7020 KB Output is correct
3 Correct 4 ms 7020 KB Output is correct
4 Correct 4 ms 7020 KB Output is correct
5 Correct 7 ms 10348 KB Output is correct
6 Correct 7 ms 10348 KB Output is correct
7 Correct 6 ms 10348 KB Output is correct
8 Correct 145 ms 173420 KB Output is correct
9 Correct 148 ms 173420 KB Output is correct
10 Correct 123 ms 173420 KB Output is correct
11 Correct 114 ms 90492 KB Output is correct
12 Correct 4 ms 7020 KB Output is correct
13 Correct 4 ms 7020 KB Output is correct
14 Correct 4 ms 7020 KB Output is correct
15 Correct 4 ms 7020 KB Output is correct
16 Correct 4 ms 7020 KB Output is correct
17 Correct 11 ms 10476 KB Output is correct
18 Correct 11 ms 8684 KB Output is correct
19 Correct 132 ms 173420 KB Output is correct
20 Correct 109 ms 62572 KB Output is correct
21 Correct 115 ms 90220 KB Output is correct
22 Correct 89 ms 62444 KB Output is correct
23 Correct 80 ms 26988 KB Output is correct
24 Correct 63 ms 40300 KB Output is correct
25 Correct 59 ms 26988 KB Output is correct
26 Correct 56 ms 26988 KB Output is correct
27 Correct 4 ms 7020 KB Output is correct
28 Correct 4 ms 7020 KB Output is correct
29 Correct 4 ms 7020 KB Output is correct
30 Correct 4 ms 7020 KB Output is correct
31 Correct 5 ms 7020 KB Output is correct
32 Correct 8 ms 10348 KB Output is correct
33 Correct 5 ms 8684 KB Output is correct
34 Correct 6 ms 7660 KB Output is correct
35 Correct 5 ms 7788 KB Output is correct
36 Correct 122 ms 173420 KB Output is correct
37 Correct 109 ms 90220 KB Output is correct
38 Correct 99 ms 62500 KB Output is correct
39 Correct 104 ms 62572 KB Output is correct
40 Correct 90 ms 62572 KB Output is correct
41 Correct 55 ms 27116 KB Output is correct
42 Correct 54 ms 26988 KB Output is correct
43 Correct 106 ms 90240 KB Output is correct
44 Correct 4 ms 7020 KB Output is correct
45 Correct 4 ms 7020 KB Output is correct
46 Correct 4 ms 7020 KB Output is correct
47 Correct 4 ms 7020 KB Output is correct
48 Correct 4 ms 7020 KB Output is correct
49 Correct 8 ms 10348 KB Output is correct
50 Correct 7 ms 8684 KB Output is correct
51 Correct 8 ms 7808 KB Output is correct
52 Correct 8 ms 7916 KB Output is correct
53 Correct 130 ms 173420 KB Output is correct
54 Correct 108 ms 62444 KB Output is correct
55 Correct 111 ms 62444 KB Output is correct
56 Correct 102 ms 62444 KB Output is correct
57 Correct 138 ms 48748 KB Output is correct
58 Correct 149 ms 173420 KB Output is correct
59 Correct 124 ms 90296 KB Output is correct