Submission #89276

#TimeUsernameProblemLanguageResultExecution timeMemory
89276BadralBeautiful row (IZhO12_beauty)C++17
100 / 100
1113 ms165124 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long ll a[55], n, b[55][55]; ll gurav(ll x) {ll s = 0; while (x) {s += (x % 3 == 1); x /= 3; } return s; } ll hoyr(ll x) {ll s = 0; while (x) {s += (x % 2 == 1); x /= 2; } return s; } ll c[1 << 20][20], ans; int main() { ll n; cin >>n; for(ll i = 0; i < n; i++) { ll x; cin >>x; a[i] = x; c[1 << i][i]++; } for(ll i = 0; i < n; i++) for(ll j = 0; j < n; j++) if(gurav(a[i]) == gurav(a[j]) || hoyr(a[i]) == hoyr(a[j])) b[i][j] = 1; for(ll i = 1; i < (1 << n); i++) for(ll j = 0; j < n; j++) { if((i >> j) & 1 ^ 1) continue; for(ll k = 0; k < n; k++) if(((i >> k) & 1 ^ 1) && b[j][k]) c[i | (1 << k)][k] += c[i][j]; } for(ll i = 0; i < n; i++) ans += c[(1 << n) - 1][i]; cout<<ans; }

Compilation message (stderr)

beauty.cpp: In function 'int main()':
beauty.cpp:28:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         if((i >> j) & 1 ^ 1) continue;
            ~~~~~~~~~^~~
beauty.cpp:30:18: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     if(((i >> k) & 1 ^ 1) && b[j][k]) 
         ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...