Submission #92695

#TimeUsernameProblemLanguageResultExecution timeMemory
92695janchomathLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
2 ms380 KiB
#include<bits/stdc++.h> #define ll int #define f first #define s second #define pb push_back using namespace std; ll n,a[5001],k[5001],dp[20][20],ans,ind,p; vector<ll>v; int main(){ std::ios::sync_with_stdio(false); cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; } for(int i=1; i<=n; i++){ cin >> k[i]; } for(int i=1; i<=n; i++)dp[i][1] = i; ans = 1; ind = 1; for(int i=1; i<=n; i++){ p = -1; for(int j = i-1; j>=1; j--){ if(__builtin_popcount((a[j]&a[i])) == k[i]){ p = j; break; } } if(p==-1)continue; for(int j=2; j<=n; j++){ if(dp[p][j-1])dp[i][j] = p; if(dp[i][j] && j > ans){ ans = j; ind = i; } } } cout << ans << endl; while(dp[ind][ans] != ind){ v.pb(ind); ind = dp[ind][ans]; ans--; } v.pb(ind); for(int i=(int)v.size()-1; i>=0; i--){ cout << v[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...