제출 #486292

#제출 시각아이디문제언어결과실행 시간메모리
486292Sho10아름다운 순열 (IZhO12_beauty)C++17
100 / 100
1621 ms127680 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define aint(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 998244353 #define PI 3.14159265359 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,check[25][25],dp[25][2000005],a[25],cnt[3][25]; int32_t main(){ CODE_START; cin>>n; for(ll i=0;i<n;i++) { cin>>a[i]; } for(ll i=0;i<n;i++) { ll x=a[i]; while(x>0){ if(x%2==1){ cnt[1][i]++; } x/=2; } x=a[i]; while(x>0){ if(x%3==1){ cnt[2][i]++; } x/=3; } } for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) { if(i!=j){ if(cnt[2][i]==cnt[2][j]){ check[i][j]=1; check[j][i]=1; }else if(cnt[1][i]==cnt[1][j]){ check[i][j]=1; check[j][i]=1; } } } } for(ll i=0;i<n;i++) { dp[i][(1ll<<(i))]=1; } for(ll mask=0;mask<(1ll<<n);mask++) { for(ll i=0;i<n;i++) { for(ll j=0;j<n;j++) { if(i==j){ continue; } if((1ll<<i)&mask==0){ continue; } if((1ll<<(j))&mask){ if(dp[i][mask-(1ll<<(j))]==0){ continue; } if(check[i][j]==0){ continue; } dp[j][mask]+=dp[i][mask-(1ll<<(j))]; } } } } ll ans=0; for(ll i=0;i<n;i++) { ans+=dp[i][(1ll<<(n))-1]; // cout<<dp[i][(1ll<<(n))-1]<<' '; } cout<<ans<<endl; }

컴파일 시 표준 에러 (stderr) 메시지

beauty.cpp: In function 'int32_t main()':
beauty.cpp:73:25: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   73 |         if((1ll<<i)&mask==0){
      |                     ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...