# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370650 | 2021-02-24T11:33:13 Z | MilosMilutinovic | Beautiful row (IZhO12_beauty) | C++14 | 848 ms | 164676 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxN = 20; int n, a[mxN]; ll dp[1<<mxN][mxN]; bool con[mxN][mxN]; int cnt(int x) { int res=0; while(x) res+=x%2, x/=2; return res; } int cnt1(int x) { int res=0; while(x) res+=(x%3==1?1:0), x/=3; return res; } int main() { cin >> n; for(int i=0; i<n; ++i) { cin >> a[i]; dp[1<<i][i]=1; } for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(cnt(a[i])==cnt(a[j])||cnt1(a[i])==cnt1(a[j])) con[i][j]=true; for(int i=1; i<(1<<n); ++i) { for(int j=0; j<n; ++j) { if(i&(1<<j)) { for(int k=0; k<n; ++k) { if((i>>k)&1^1&&con[j][k]){ dp[i|(1<<k)][k]+=dp[i][j]; } } } } } ll ans = 0; for(int i=0; i<n; ++i) ans+=dp[(1<<n)-1][i]; cout << ans << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 492 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 492 KB | Output is correct |
11 | Correct | 9 ms | 2924 KB | Output is correct |
12 | Correct | 8 ms | 2924 KB | Output is correct |
13 | Correct | 37 ms | 10604 KB | Output is correct |
14 | Correct | 180 ms | 41452 KB | Output is correct |
15 | Correct | 155 ms | 41468 KB | Output is correct |
16 | Correct | 183 ms | 41452 KB | Output is correct |
17 | Correct | 189 ms | 41324 KB | Output is correct |
18 | Correct | 190 ms | 41324 KB | Output is correct |
19 | Correct | 848 ms | 164676 KB | Output is correct |
20 | Correct | 700 ms | 164500 KB | Output is correct |