# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
685723 | 2023-01-24T22:11:37 Z | Summers | 아름다운 순열 (IZhO12_beauty) | C++14 | 3000 ms | 1748 KB |
#include<bits/stdc++.h> #include<vector> #define endl '\n' using namespace std; int a[1000000], b[1000000], dp[(1<<22)][23], n; int rec(int mask, int last) { if(mask==((1<<n)-1)) return 1; if(last!=-1 && dp[mask][last]!=0)return dp[mask][last]; int an=0; for(int i=0;i<n;i++) { if(!(mask&(1<<i))) { if(last==-1 || (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); int i,j,t,p,p1, ans=0; cin>>n; for(i=0;i<n;i++) { cin>>p; a[i]=__builtin_popcount(p); p1=p; while(p1>0) { if(p1%3==1)b[i]++; p1/=3; } } ans+=rec(0,-1); cout<<ans<<endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 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 | 340 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Execution timed out | 3017 ms | 1748 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |