# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685714 | 2023-01-24T21:50:20 Z | Summers | Beautiful row (IZhO12_beauty) | C++14 | 3000 ms | 3200 KB |
#include<bits/stdc++.h> #include<vector> #define endl '\n' using namespace std; long long a[1000000], b[1000000], dp[(1<<21)][23], n; long long rec(long long mask, long long last) { if(mask==((1<<n)-1)) return 1; if(dp[mask][last]!=0)return dp[mask][last]; long long an=0; for(int i=0;i<n;i++) { if((mask&(1<<i))==0) { if(a[last]==a[i] || b[last]==b[i]) { an+=rec(mask|(1<<i), i); } } } return dp[mask][last]=an; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long i,j,t,p,p1, ans=0; cin>>n; for(i=0;i<n;i++) { cin>>p; p1=p; while(p>0) { a[i]+=p%2; p/=2; } while(p1>0) { if(p1%3==1)b[i]++; p1/=3; } } for(i=0;i<n;i++)ans+=rec((1<<i),i); cout<<ans<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 276 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 468 KB | Output is correct |
7 | Correct | 1 ms | 456 KB | Output is correct |
8 | Correct | 1 ms | 456 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 2 ms | 468 KB | Output is correct |
11 | Execution timed out | 3080 ms | 3200 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |