Submission #89279

# Submission time Handle Problem Language Result Execution time Memory
89279 2018-12-11T09:27:38 Z turbat Beautiful row (IZhO12_beauty) C++14
0 / 100
1230 ms 263168 KB
#include <bits/stdc++.h>
using namespace std; 

long long n, m, a[25], dp[1000005][25], ans, cnt[25], cnt1[25];

int main (){	
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		cnt[i] = __builtin_popcount(a[i]);
		m = a[i];
		while (m){
			if (m % 3 == 1) cnt1[i]++;
			m /= 3;
		}
	}
	for (int i = 0;i < n;i++) dp[1 << i][i] = 1;
	for (int i = 0;i < (1 << n);i++)
		for (int j = 0;j < n;j++)
			for (int o = 0;o < n;o++)
				if (!(i & 1<<o) && (cnt[j] == cnt[o] || cnt1[j] == cnt1[o]))
					dp[i|(1<<o)][o] += dp[i][j];
	for (int i = 0;i < n;i++) ans += dp[(1<<n) - 1][i];
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 3 ms 668 KB Output is correct
7 Correct 3 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 3 ms 808 KB Output is correct
10 Correct 3 ms 808 KB Output is correct
11 Correct 17 ms 3640 KB Output is correct
12 Correct 16 ms 3640 KB Output is correct
13 Correct 70 ms 13368 KB Output is correct
14 Correct 350 ms 51864 KB Output is correct
15 Correct 246 ms 51864 KB Output is correct
16 Correct 347 ms 52008 KB Output is correct
17 Correct 394 ms 52008 KB Output is correct
18 Correct 397 ms 52008 KB Output is correct
19 Runtime error 1230 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -