Submission #227631

# Submission time Handle Problem Language Result Execution time Memory
227631 2020-04-28T07:49:00 Z bensonlzl Paths (BOI18_paths) C++14
100 / 100
656 ms 172408 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll sum = 0, dp[2][300005][(1 << 5)];
vector<int> AdjList[300005];
int N, M, K, X, Y, colour[300005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M >> K;
	for (int i = 1; i <= N; ++i){
		cin >> colour[i];
		colour[i]--;
	}
	for (int i = 1; i <= M; ++i){
		cin >> X >> Y;
		AdjList[X].push_back(Y);
		AdjList[Y].push_back(X);
	}
	for (int i = 1; i <= N; ++i){
		for (int mask = 0; mask < (1 << 5); ++mask){
			dp[0][i][mask] = dp[1][i][mask] = 0;
		}
		dp[0][i][(1 << colour[i])] = 1;
	}
	for (int i = 1; i < K; ++i){
		for (int v = 1; v <= N; ++v){
			for (int mask = 0; mask < (1 << 5); ++mask){
				dp[i&1][v][mask] = 0;
				if ((mask & (1 << colour[v])) == 0) continue;
				for (auto it : AdjList[v]){
					dp[i&1][v][mask] += dp[(i-1)&1][it][mask ^ (1 << colour[v])];
				}
				sum += dp[i&1][v][mask];
			}
		}
	}
	cout << sum << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7456 KB Output is correct
7 Correct 9 ms 7552 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 16504 KB Output is correct
2 Correct 87 ms 13560 KB Output is correct
3 Correct 505 ms 171868 KB Output is correct
4 Correct 156 ms 30392 KB Output is correct
5 Correct 117 ms 30328 KB Output is correct
6 Correct 448 ms 119696 KB Output is correct
7 Correct 503 ms 171620 KB Output is correct
8 Correct 553 ms 172408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 10 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7456 KB Output is correct
7 Correct 9 ms 7552 KB Output is correct
8 Correct 9 ms 7424 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
11 Correct 115 ms 16504 KB Output is correct
12 Correct 87 ms 13560 KB Output is correct
13 Correct 505 ms 171868 KB Output is correct
14 Correct 156 ms 30392 KB Output is correct
15 Correct 117 ms 30328 KB Output is correct
16 Correct 448 ms 119696 KB Output is correct
17 Correct 503 ms 171620 KB Output is correct
18 Correct 553 ms 172408 KB Output is correct
19 Correct 106 ms 16376 KB Output is correct
20 Correct 93 ms 13688 KB Output is correct
21 Correct 511 ms 171768 KB Output is correct
22 Correct 146 ms 30328 KB Output is correct
23 Correct 125 ms 30328 KB Output is correct
24 Correct 412 ms 119532 KB Output is correct
25 Correct 517 ms 171808 KB Output is correct
26 Correct 524 ms 172408 KB Output is correct
27 Correct 102 ms 13560 KB Output is correct
28 Correct 148 ms 18680 KB Output is correct
29 Correct 656 ms 171868 KB Output is correct
30 Correct 454 ms 93036 KB Output is correct
31 Correct 439 ms 93036 KB Output is correct
32 Correct 624 ms 171756 KB Output is correct
33 Correct 9 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 9 ms 7424 KB Output is correct
36 Correct 9 ms 7424 KB Output is correct
37 Correct 9 ms 7424 KB Output is correct
38 Correct 9 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 8 ms 7424 KB Output is correct
41 Correct 9 ms 7424 KB Output is correct
42 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 44 ms 9472 KB Output is correct
3 Correct 35 ms 9472 KB Output is correct
4 Correct 173 ms 62084 KB Output is correct
5 Correct 148 ms 62828 KB Output is correct
6 Correct 223 ms 62076 KB Output is correct
7 Correct 39 ms 9472 KB Output is correct
8 Correct 193 ms 62072 KB Output is correct
9 Correct 173 ms 62832 KB Output is correct
10 Correct 195 ms 62728 KB Output is correct
11 Correct 158 ms 35676 KB Output is correct
12 Correct 175 ms 49392 KB Output is correct
13 Correct 155 ms 35696 KB Output is correct
14 Correct 213 ms 62072 KB Output is correct
15 Correct 219 ms 62072 KB Output is correct
16 Correct 8 ms 7456 KB Output is correct
17 Correct 8 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 8 ms 7424 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 8 ms 7424 KB Output is correct