Submission #715890

#TimeUsernameProblemLanguageResultExecution timeMemory
715890mychecksedadBeautiful row (IZhO12_beauty)C++17
0 / 100
32 ms6724 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define all(x) x.begin(), x.end() const int N = 25, M = 1e5+10, K = 20; int n, a[N], b[N][N], bin[N], ter[N], dp[1<<K][N]; void solve(){ cin >> n; for(int i = 0; i < n; ++i) cin >> a[i]; for(int i = 0; i < n; ++i) bin[i] = __builtin_popcount(a[i]); for(int i = 0; i < n; ++i){ ter[i] = 0; int v = a[i]; while(v > 0){ if(v % 3 == 1) ter[i]++; v /= 3; } } for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ b[i][j] = (bin[i] == bin[j] || ter[i] == ter[j]); } } for(int i = 0; i < (1<<n); ++i){ for(int j = 0; j < n; ++j) dp[i][j] = 0; if(__builtin_popcount(i) == 1){ for(int j = 0; j < n; ++j){ if((1<<j)&i) dp[i][j] = 1; } } } for(int mask = 1; mask < (1<<n); ++mask){ for(int j = 0; j < n; ++j){ if(!((1<<j)&mask)){ for(int k = 0; k < n; ++k){ if((1<<k)&mask){ if(b[j][k] == 1) dp[mask ^ (1<<j)][j] += dp[mask][k]; } } } } } // for(int i =0 ; i < (1<<n); ++i){ // for(int j = 0; j < n; ++j){ // cout << dp[i][j] << ' '; // } // cout << '\n'; // } ll ans = 0; for(int i = 0; i < n; ++i) ans += dp[(1<<n) - 1][i]; cout << ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

Compilation message (stderr)

beauty.cpp: In function 'int main()':
beauty.cpp:69:14: warning: unused variable 'aa' [-Wunused-variable]
   69 |   int T = 1, aa;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...