Submission #894616

#TimeUsernameProblemLanguageResultExecution timeMemory
894616AndreyBeautiful row (IZhO12_beauty)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; int dp[(1 << 20)][20]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,a; cin >> n; vector<int> haha(n); for(int i = 0; i < n; i++) { cin >> haha[i]; } vector<int> br2(n); vector<int> br3(n); for(int i = 0; i < n; i++) { a = haha[i]; while(a > 0) { br2[i]+=a%2; a/=2; } a = haha[i]; while(a > 0) { if(a%3 == 1) { br3[i]+=1; } a/=3; } } int ans = 1; for(int i = 1; i < (1 << n); i++) { for(int j = 0; j < n; j++) { if((1 << j)&i) { int c = i-(1 << j); dp[i][j] = -1; if(c == 0) { dp[i][j] = 1; } else { for(int k = 0; k < n; k++) { if(((1 << k)&c) && (br2[k] == br2[j] || br3[k] == br3[j])) { if(dp[c][k] != -1) { dp[i][j] = dp[c][k]+1; break; } } } } } else { dp[i][j] = -1; } ans = max(ans,dp[i][j]); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...