답안 #1092127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092127 2024-09-23T09:18:21 Z lovrot Paths (BOI18_paths) C++17
100 / 100
216 ms 97216 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define PB push_back

using namespace std; 

typedef long long ll;

const int N = 3e5 + 10;
const int K = 5;

int n, m, k, c[N];
vector<int> g[N];

ll dp[N][1 << K];

int next_perm(int x, int k) {
	int ret = x + (x & -x);
	return ret + (1 << (k - __builtin_popcount(ret))) - 1;
}

char out[K];

char* bit(int x) { 
	for(int i = 0; i < k; ++i) { 
		out[i] = '0' + (bool) (x & (1 << i));
	}
	return out;
}

int main() { 
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", c + i);
		-- c[i];
		dp[i][1 << c[i]] = 1;
	}
	for(int i = 0; i < m; ++i) { 
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].PB(v);
		g[v].PB(u);
	}

	ll ans = 0;
	for(int i = 2; i <= k; ++i) { 
		int mask = (1 << i) - 1;
		for(; mask < (1 << k); mask = next_perm(mask, i)) {
//			printf("%d %.*s\n", mask, k, bit(mask));
			for(int u = 1; u <= n; ++u) { 
				if(mask & (1 << c[u])) { 
					for(int v : g[u]) { 
						dp[u][mask] += dp[v][mask ^ (1 << c[u])];
					}
//					if(i == 2) { printf("%d %lld\n", u, dp[u][mask]); }
					ans += dp[u][mask];
				}
			}
		}
	}

	printf("%lld\n", ans);
	return 0;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
paths.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d", c + i);
      |   ~~~~~^~~~~~~~~~~~~
paths.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d%d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7488 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 3 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 15144 KB Output is correct
2 Correct 38 ms 13364 KB Output is correct
3 Correct 166 ms 96592 KB Output is correct
4 Correct 65 ms 22864 KB Output is correct
5 Correct 79 ms 22752 KB Output is correct
6 Correct 125 ms 69300 KB Output is correct
7 Correct 162 ms 96592 KB Output is correct
8 Correct 166 ms 97068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7260 KB Output is correct
4 Correct 3 ms 7488 KB Output is correct
5 Correct 3 ms 7256 KB Output is correct
6 Correct 5 ms 7516 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
9 Correct 3 ms 7260 KB Output is correct
10 Correct 3 ms 7260 KB Output is correct
11 Correct 51 ms 15144 KB Output is correct
12 Correct 38 ms 13364 KB Output is correct
13 Correct 166 ms 96592 KB Output is correct
14 Correct 65 ms 22864 KB Output is correct
15 Correct 79 ms 22752 KB Output is correct
16 Correct 125 ms 69300 KB Output is correct
17 Correct 162 ms 96592 KB Output is correct
18 Correct 166 ms 97068 KB Output is correct
19 Correct 49 ms 15184 KB Output is correct
20 Correct 39 ms 13396 KB Output is correct
21 Correct 184 ms 96592 KB Output is correct
22 Correct 70 ms 22864 KB Output is correct
23 Correct 69 ms 22880 KB Output is correct
24 Correct 131 ms 69484 KB Output is correct
25 Correct 173 ms 96596 KB Output is correct
26 Correct 180 ms 97216 KB Output is correct
27 Correct 43 ms 13400 KB Output is correct
28 Correct 75 ms 16748 KB Output is correct
29 Correct 216 ms 96596 KB Output is correct
30 Correct 156 ms 55348 KB Output is correct
31 Correct 190 ms 55452 KB Output is correct
32 Correct 212 ms 96596 KB Output is correct
33 Correct 4 ms 7516 KB Output is correct
34 Correct 3 ms 7516 KB Output is correct
35 Correct 3 ms 7256 KB Output is correct
36 Correct 4 ms 7260 KB Output is correct
37 Correct 3 ms 7256 KB Output is correct
38 Correct 3 ms 7516 KB Output is correct
39 Correct 4 ms 7324 KB Output is correct
40 Correct 3 ms 7512 KB Output is correct
41 Correct 3 ms 7260 KB Output is correct
42 Correct 3 ms 7484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7260 KB Output is correct
2 Correct 16 ms 9308 KB Output is correct
3 Correct 15 ms 9308 KB Output is correct
4 Correct 45 ms 36948 KB Output is correct
5 Correct 42 ms 37580 KB Output is correct
6 Correct 79 ms 36920 KB Output is correct
7 Correct 15 ms 9304 KB Output is correct
8 Correct 75 ms 36860 KB Output is correct
9 Correct 46 ms 37588 KB Output is correct
10 Correct 62 ms 37836 KB Output is correct
11 Correct 41 ms 22988 KB Output is correct
12 Correct 52 ms 30592 KB Output is correct
13 Correct 43 ms 23388 KB Output is correct
14 Correct 76 ms 36948 KB Output is correct
15 Correct 74 ms 36948 KB Output is correct
16 Correct 3 ms 7260 KB Output is correct
17 Correct 3 ms 7516 KB Output is correct
18 Correct 3 ms 7260 KB Output is correct
19 Correct 3 ms 7260 KB Output is correct
20 Correct 2 ms 7260 KB Output is correct
21 Correct 3 ms 7364 KB Output is correct
22 Correct 4 ms 7260 KB Output is correct
23 Correct 3 ms 7516 KB Output is correct
24 Correct 3 ms 7260 KB Output is correct
25 Correct 4 ms 7328 KB Output is correct