Submission #648433

# Submission time Handle Problem Language Result Execution time Memory
648433 2022-10-06T13:22:56 Z ymm Toll (BOI17_toll) C++17
100 / 100
2411 ms 7012 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

typedef unsigned int vec __attribute__((vector_size(32), aligned(4)));
const int N = 50'016;
vec toll[N];
vec mask[N];
unsigned int dis[N];
int n, m, k, o;

#define SMIN(x, y) ((x)=(x)<(y)?(x):(y))

int order(int v, int u)
{
	const int k = ::k;
	fill(dis+v, dis+u+1, (1u<<31)-1);
	dis[v] = 0;
	while (v%k) {
		SMIN(*(vec *)(dis + v+k-v%k), (dis[v] + toll[v]) | mask[v]);
		++v;
	}
	const int vk = v/k; // vulkan
	const int uk = u/k; // united kingdom
	Loop (i,vk,uk) {
		const int ki = i*k;
		Loop (x,0,k) {
			SMIN(*(vec *)(dis+ki+k), 
			     (dis[ki+x] + toll[ki+x]) | mask[ki+x]);
		}
	}
	return dis[u] == (1u<<31)-1? -1: dis[u];
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	fill(mask, mask+N, vec{~0u, ~0u, ~0u, ~0u, ~0u, ~0u, ~0u, ~0u});
	cin >> k >> n >> m >> o;
	Loop (i,0,m) {
		int v, u, w;
		cin >> v >> u >> w;
		toll[v][u%k] = w;
		mask[v][u%k] = 0;
	}
	while (o--) {
		int v, u;
		cin >> v >> u;
		cout << order(v, u) << '\n';
	};
}
# Verdict Execution time Memory Grader output
1 Correct 1671 ms 4832 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 5 ms 1908 KB Output is correct
7 Correct 5 ms 1876 KB Output is correct
8 Correct 1637 ms 4576 KB Output is correct
9 Correct 1621 ms 4640 KB Output is correct
10 Correct 1618 ms 2248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1292 ms 5380 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1900 KB Output is correct
7 Correct 53 ms 2008 KB Output is correct
8 Correct 29 ms 2056 KB Output is correct
9 Correct 2411 ms 4536 KB Output is correct
10 Correct 1083 ms 6120 KB Output is correct
11 Correct 1278 ms 5356 KB Output is correct
12 Correct 1057 ms 4948 KB Output is correct
13 Correct 172 ms 5348 KB Output is correct
14 Correct 219 ms 4340 KB Output is correct
15 Correct 156 ms 4148 KB Output is correct
16 Correct 156 ms 4100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 3 ms 1876 KB Output is correct
9 Correct 2 ms 1912 KB Output is correct
10 Correct 34 ms 4436 KB Output is correct
11 Correct 38 ms 5100 KB Output is correct
12 Correct 49 ms 5708 KB Output is correct
13 Correct 48 ms 5988 KB Output is correct
14 Correct 41 ms 5440 KB Output is correct
15 Correct 27 ms 4044 KB Output is correct
16 Correct 24 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 3 ms 1876 KB Output is correct
9 Correct 2 ms 1912 KB Output is correct
10 Correct 34 ms 4436 KB Output is correct
11 Correct 38 ms 5100 KB Output is correct
12 Correct 49 ms 5708 KB Output is correct
13 Correct 48 ms 5988 KB Output is correct
14 Correct 41 ms 5440 KB Output is correct
15 Correct 27 ms 4044 KB Output is correct
16 Correct 24 ms 4044 KB Output is correct
17 Correct 284 ms 5192 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1900 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 12 ms 1912 KB Output is correct
24 Correct 7 ms 1912 KB Output is correct
25 Correct 6 ms 1912 KB Output is correct
26 Correct 5 ms 1912 KB Output is correct
27 Correct 506 ms 4472 KB Output is correct
28 Correct 241 ms 5836 KB Output is correct
29 Correct 253 ms 6108 KB Output is correct
30 Correct 249 ms 5492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1671 ms 4832 KB Output is correct
2 Correct 1 ms 1900 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 5 ms 1876 KB Output is correct
6 Correct 5 ms 1908 KB Output is correct
7 Correct 5 ms 1876 KB Output is correct
8 Correct 1637 ms 4576 KB Output is correct
9 Correct 1621 ms 4640 KB Output is correct
10 Correct 1618 ms 2248 KB Output is correct
11 Correct 1292 ms 5380 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
16 Correct 1 ms 1900 KB Output is correct
17 Correct 53 ms 2008 KB Output is correct
18 Correct 29 ms 2056 KB Output is correct
19 Correct 2411 ms 4536 KB Output is correct
20 Correct 1083 ms 6120 KB Output is correct
21 Correct 1278 ms 5356 KB Output is correct
22 Correct 1057 ms 4948 KB Output is correct
23 Correct 172 ms 5348 KB Output is correct
24 Correct 219 ms 4340 KB Output is correct
25 Correct 156 ms 4148 KB Output is correct
26 Correct 156 ms 4100 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1900 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 3 ms 1876 KB Output is correct
35 Correct 2 ms 1912 KB Output is correct
36 Correct 34 ms 4436 KB Output is correct
37 Correct 38 ms 5100 KB Output is correct
38 Correct 49 ms 5708 KB Output is correct
39 Correct 48 ms 5988 KB Output is correct
40 Correct 41 ms 5440 KB Output is correct
41 Correct 27 ms 4044 KB Output is correct
42 Correct 24 ms 4044 KB Output is correct
43 Correct 284 ms 5192 KB Output is correct
44 Correct 1 ms 1876 KB Output is correct
45 Correct 1 ms 1876 KB Output is correct
46 Correct 1 ms 1900 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1876 KB Output is correct
49 Correct 12 ms 1912 KB Output is correct
50 Correct 7 ms 1912 KB Output is correct
51 Correct 6 ms 1912 KB Output is correct
52 Correct 5 ms 1912 KB Output is correct
53 Correct 506 ms 4472 KB Output is correct
54 Correct 241 ms 5836 KB Output is correct
55 Correct 253 ms 6108 KB Output is correct
56 Correct 249 ms 5492 KB Output is correct
57 Correct 387 ms 7012 KB Output is correct
58 Correct 1622 ms 4680 KB Output is correct
59 Correct 893 ms 5496 KB Output is correct