# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011383 | 2024-06-30T12:50:48 Z | AndrijaM | Beautiful row (IZhO12_beauty) | C++14 | 718 ms | 164588 KB |
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn=500; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; int x[n+1]; int b[n+1]; int t[n+1]; memset(t,0,sizeof t); for(int i=0;i<n;i++) { cin>>x[i]; b[i]=__builtin_popcount(x[i]); vector<int>v; int num=x[i]; while(num>0) { int val=num%3; num/=3; v.push_back(val); } for(int idx=0;idx<v.size();idx++) { if(v[idx]==1) t[i]++; } } int dp[n][(1<<n)]; memset(dp,0,sizeof dp); for(int i=0;i<n;i++) { for(int k=0;(1<<k)<(1<<n);k++) { dp[i][(1<<k)]=1; } } for(int i=1;i<(1<<n);i++) { for(int prev=0;prev<n;prev++) { if(i&(1<<prev)) { for(int bit=0;bit<n;bit++) { if(i&(1<<bit)) { } else { int M=i; M|=(1<<bit); if(b[prev]==b[bit] || t[prev]==t[bit]) dp[bit][M]+=dp[prev][i]; } } } } } int ans=0; for(int i=0;i<n;i++) { ans+=dp[i][(1<<n)-1]; } cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 352 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 7 ms | 2084 KB | Output is correct |
12 | Correct | 7 ms | 2140 KB | Output is correct |
13 | Correct | 31 ms | 8540 KB | Output is correct |
14 | Correct | 152 ms | 37364 KB | Output is correct |
15 | Correct | 135 ms | 37208 KB | Output is correct |
16 | Correct | 145 ms | 37260 KB | Output is correct |
17 | Correct | 156 ms | 37368 KB | Output is correct |
18 | Correct | 167 ms | 37208 KB | Output is correct |
19 | Correct | 718 ms | 164588 KB | Output is correct |
20 | Correct | 581 ms | 164440 KB | Output is correct |