Submission #894934

#TimeUsernameProblemLanguageResultExecution timeMemory
894934raul2008487Beautiful row (IZhO12_beauty)C++17
0 / 100
3056 ms452 KiB
#include <bits/stdc++.h> #define ll long long #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define vl vector<ll> #define fi first #define se second #define in insert #define mpr make_pair #define lg(x) __lg(x) #define bpc(x) __builtin_popcount(x) #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int mod = 998244353; vl adj[25]; bool used[25]; ll ans, n; void dfs(ll v, ll depth){ used[v] = 1; if(depth == n){ ans++; used[v] = 0; return ; } for(auto edge: adj[v]){ if(!used[edge]){ dfs(edge, depth + 1); } } used[v] = 0; } void solve() { ll i, j; cin>>n; vl a(n); vector<pll> v(n); for(i=0;i<n;i++){ cin>>a[i]; v[i].fi = bpc(a[i]); ll lg = 20, cnt = 0, d = a[i]; while(d){ ll dv = pow(3, lg); lg--; if(dv > d){continue;} ll df = d / dv; cnt += (df == 1); d %= dv; } v[i].se = cnt; } for(i=0;i<n;i++){ for(j = i+1;j<n;j++){ if(v[i].fi == v[j].fi || v[i].se == v[j].se){ adj[i].pb(j); adj[j].pb(i); } } } for(i=0;i<n;i++){ dfs(i, 1); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //precomp(); ll tst=1; //cin>>tst; while(tst--){ solve(); } } /* ok. */
#Verdict Execution timeMemoryGrader output
Fetching results...