Submission #669683

#TimeUsernameProblemLanguageResultExecution timeMemory
669683sudheerays123Beautiful row (IZhO12_beauty)C++17
0 / 100
2 ms724 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ll long long int const ll N = 12 , INF = 1e18 , MOD = 1e9+7; ll n; vector<ll> a(N); ll dp[(1ll<<N)][N]; ll log_a_to_base_b(ll a, ll b){ return log2(a) / log2(b); } ll expo(ll a , ll b){ if(b == 0) return 1; if(b == 1) return a; ll p = expo(a,b/2); if(b%2 == 0) return (p*p); return (p*p*a); } ll countone(ll x){ ll l = log_a_to_base_b(x,3); ll cnt = 0; ll s = expo(3,l); while(x > 0){ ll p = x/s; x -= s*p; if(p == 1) cnt++; s /= 3; } return cnt; } ll go(ll mask , ll last){ if(__builtin_popcountll(mask) == n) return 1; if(dp[mask][last] != -1) return dp[mask][last]; ll ans = 0; for(ll i = 1; i <= n; i++){ if(mask&(1ll<<i)) continue; if(last != 0 && __builtin_popcountll(a[last]) == __builtin_popcountll(a[i])) ans += go(mask|(1ll<<i),i); else if(last != 0 && countone(a[last]) == countone(a[i])) ans += go(mask|(1ll<<i),i); else if(last == 0) ans += go(mask|(1ll<<i),i); } return dp[mask][last] = ans; } void solve(){ cin >> n; for(ll i = 1; i <= n; i++) cin >> a[i]; memset(dp,-1,sizeof dp); cout << go(0,0); } int main(){ fast; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll tc = 1; // cin >> tc; while(tc--) solve(); return 0; }

Compilation message (stderr)

beauty.cpp: In function 'int main()':
beauty.cpp:71:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   freopen("input.txt","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
beauty.cpp:72:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   freopen("output.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...