Submission #730852

# Submission time Handle Problem Language Result Execution time Memory
730852 2023-04-26T14:25:43 Z rainboy Beautiful row (IZhO12_beauty) C
100 / 100
736 ms 164420 KB
#include <stdio.h>

#define N	20

int ones(int n, int b) {
	return n == 0 ? 0 : ones(n / b, b) + (n % b == 1 ? 1 : 0);
}

int main() {
	static int aa[N];
	static char adj[N][N];
	static long long dp[1 << N][N];
	int n, i, j, b;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			adj[i][j] = ones(aa[i], 2) == ones(aa[j], 2) || ones(aa[i], 3) == ones(aa[j], 3);
	for (i = 0; i < n; i++)
		dp[1 << i][i] = 1;
	for (b = 0; b < 1 << n; b++)
		for (i = 0; i < n; i++) {
			long long x = dp[b][i];

			if (x == 0)
				continue;
			for (j = 0; j < n; j++)
				if ((b & 1 << j) == 0 && adj[i][j])
					dp[b | 1 << j][j] += dp[b][i];
		}
	b = (1 << n) - 1;
	ans = 0;
	for (i = 0; i < n; i++)
		ans += dp[b][i];
	printf("%lld\n", ans);
	return 0;
}

Compilation message

beauty.c: In function 'main':
beauty.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
beauty.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 2772 KB Output is correct
12 Correct 6 ms 2736 KB Output is correct
13 Correct 32 ms 10532 KB Output is correct
14 Correct 154 ms 41272 KB Output is correct
15 Correct 142 ms 41260 KB Output is correct
16 Correct 137 ms 41308 KB Output is correct
17 Correct 179 ms 41344 KB Output is correct
18 Correct 148 ms 41420 KB Output is correct
19 Correct 736 ms 164348 KB Output is correct
20 Correct 655 ms 164420 KB Output is correct