# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922679 | 2024-02-06T01:25:03 Z | thunopro | Beautiful row (IZhO12_beauty) | C++14 | 957 ms | 164620 KB |
//Just try and the idea will come! #include<bits/stdc++.h> #define int long long int using namespace std; int n,i,a[20],dp[1048576][20],ans,j,tri[20],bin[20],mask; main(){ scanf("%lld",&n); for(;i<n;i++){ scanf("%lld",&a[i]); dp[1<<i][i]=1; bin[i]=__builtin_popcount(a[i]); mask=a[i]; while(mask){ if(mask%3==1)tri[i]++; mask/=3; } } for(mask=0;mask<(1<<n);mask++) for(i=0;i<n;i++) if(mask&(1<<i)) for(j=0;j<n;j++) if(i!=j) if(mask&(1<<j)&&(tri[i]==tri[j]||bin[i]==bin[j]))dp[mask][i]+=dp[mask^(1<<i)][j]; for(i=0;i<n;i++)ans+=dp[(1<<n)-1][i]; printf("%lld",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 604 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 600 KB | Output is correct |
11 | Correct | 9 ms | 4700 KB | Output is correct |
12 | Correct | 9 ms | 4700 KB | Output is correct |
13 | Correct | 42 ms | 10852 KB | Output is correct |
14 | Correct | 200 ms | 41344 KB | Output is correct |
15 | Correct | 193 ms | 41556 KB | Output is correct |
16 | Correct | 204 ms | 41592 KB | Output is correct |
17 | Correct | 198 ms | 41552 KB | Output is correct |
18 | Correct | 202 ms | 41556 KB | Output is correct |
19 | Correct | 957 ms | 164612 KB | Output is correct |
20 | Correct | 909 ms | 164620 KB | Output is correct |