# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673813 | 2022-12-22T05:40:27 Z | smartmonky | Beautiful row (IZhO12_beauty) | C++14 | 230 ms | 262144 KB |
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} const int N = (1 << 21) + 2; long long dp[N][25]; int a[21], bit[21], ter[21]; long long ful; int getbits(int x){ int res = 0; while(x > 0){ res += x % 2; x >>= 1; } return res; } int getter(int x){ int res = 0; while(x > 0){ res += (x % 3 == 1); x /= 3; } return res; } main(){ int n; cin >> n; for(int i = 1; i <= n; i++){ ful += (1 << i); cin >> a[i]; bit[i] = getbits(a[i]); ter[i] = getter(a[i]); dp[(1 << i)][i] = 1; } for(int i = 1; i < (1 << (n + 1)); i++){ for(int j = 1; j <= n; j++){ if(dp[i][j] == 0 || (i & (1 << j)) == 0)continue; for(int k = 1; k <= n; k++){ if((i & (1 << k)))continue; if(bit[k] == bit[j] || ter[k] == ter[j]) dp[i + (1 << k)][k] += dp[i][j]; } } } long long ans = 0; for(int i = 1; i <= n; i++){ ans += dp[ful][i]; } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 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 | 596 KB | Output is correct |
7 | Correct | 1 ms | 596 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 1 ms | 596 KB | Output is correct |
10 | Correct | 1 ms | 596 KB | Output is correct |
11 | Correct | 10 ms | 6356 KB | Output is correct |
12 | Correct | 9 ms | 6612 KB | Output is correct |
13 | Correct | 38 ms | 25876 KB | Output is correct |
14 | Correct | 172 ms | 102884 KB | Output is correct |
15 | Correct | 162 ms | 102888 KB | Output is correct |
16 | Correct | 181 ms | 102880 KB | Output is correct |
17 | Correct | 191 ms | 102796 KB | Output is correct |
18 | Correct | 159 ms | 102860 KB | Output is correct |
19 | Runtime error | 230 ms | 262144 KB | Execution killed with signal 9 |
20 | Halted | 0 ms | 0 KB | - |