답안 #328896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
328896 2020-11-18T12:03:53 Z syy Toll (BOI17_toll) C++17
100 / 100
145 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];
	//~ FOR(i, 0, n/k-1) FOR(t, 0, 2) cout << i << " " << t << " " << p[i][t] << "\n";
	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]);
	}
	//~ FOR(i, 0, n/k-1) FOR(t, 0, 1) FOR(j, 0, k-1) FOR(l, 0, k-1) printf("%lld %lld %lld %lld: %lld\n", i, t, j, l, dist[i][t][j][l]);
	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) {
			//~ cout << "considering " << x << " to " << p[x][t] << "\n";
			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]);
				//~ cout << "best: " << best.f << " " << best.s << "\n";
			pos = newpos;
			x = p[x][t];
		}
		cout << (pos[b%k] == LLINF ? -1 : pos[b%k]) << "\n";
		//~ for (auto [d, it]:pos) if (it == b%k) ans = min(ans, d);
		//~ cout << (ans == LLINF ? -1 : ans) << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 145 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 144 ms 173420 KB Output is correct
9 Correct 142 ms 173420 KB Output is correct
10 Correct 130 ms 173420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 90348 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 5 ms 7020 KB Output is correct
7 Correct 11 ms 10348 KB Output is correct
8 Correct 11 ms 8684 KB Output is correct
9 Correct 133 ms 173420 KB Output is correct
10 Correct 110 ms 62572 KB Output is correct
11 Correct 116 ms 90348 KB Output is correct
12 Correct 92 ms 62772 KB Output is correct
13 Correct 80 ms 26988 KB Output is correct
14 Correct 73 ms 40300 KB Output is correct
15 Correct 60 ms 26988 KB Output is correct
16 Correct 55 ms 26988 KB Output is correct
# 결과 실행 시간 메모리 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 6 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 134 ms 173420 KB Output is correct
11 Correct 103 ms 90220 KB Output is correct
12 Correct 100 ms 62572 KB Output is correct
13 Correct 106 ms 62444 KB Output is correct
14 Correct 91 ms 62444 KB Output is correct
15 Correct 55 ms 26988 KB Output is correct
16 Correct 54 ms 27116 KB Output is correct
# 결과 실행 시간 메모리 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 6 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 134 ms 173420 KB Output is correct
11 Correct 103 ms 90220 KB Output is correct
12 Correct 100 ms 62572 KB Output is correct
13 Correct 106 ms 62444 KB Output is correct
14 Correct 91 ms 62444 KB Output is correct
15 Correct 55 ms 26988 KB Output is correct
16 Correct 54 ms 27116 KB Output is correct
17 Correct 108 ms 90220 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 7148 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 7660 KB Output is correct
26 Correct 7 ms 7916 KB Output is correct
27 Correct 127 ms 173420 KB Output is correct
28 Correct 107 ms 62444 KB Output is correct
29 Correct 110 ms 62572 KB Output is correct
30 Correct 96 ms 62444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 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 144 ms 173420 KB Output is correct
9 Correct 142 ms 173420 KB Output is correct
10 Correct 130 ms 173420 KB Output is correct
11 Correct 133 ms 90348 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 5 ms 7020 KB Output is correct
17 Correct 11 ms 10348 KB Output is correct
18 Correct 11 ms 8684 KB Output is correct
19 Correct 133 ms 173420 KB Output is correct
20 Correct 110 ms 62572 KB Output is correct
21 Correct 116 ms 90348 KB Output is correct
22 Correct 92 ms 62772 KB Output is correct
23 Correct 80 ms 26988 KB Output is correct
24 Correct 73 ms 40300 KB Output is correct
25 Correct 60 ms 26988 KB Output is correct
26 Correct 55 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 6 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 134 ms 173420 KB Output is correct
37 Correct 103 ms 90220 KB Output is correct
38 Correct 100 ms 62572 KB Output is correct
39 Correct 106 ms 62444 KB Output is correct
40 Correct 91 ms 62444 KB Output is correct
41 Correct 55 ms 26988 KB Output is correct
42 Correct 54 ms 27116 KB Output is correct
43 Correct 108 ms 90220 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 7148 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 7660 KB Output is correct
52 Correct 7 ms 7916 KB Output is correct
53 Correct 127 ms 173420 KB Output is correct
54 Correct 107 ms 62444 KB Output is correct
55 Correct 110 ms 62572 KB Output is correct
56 Correct 96 ms 62444 KB Output is correct
57 Correct 136 ms 48748 KB Output is correct
58 Correct 144 ms 173420 KB Output is correct
59 Correct 126 ms 90220 KB Output is correct