Submission #1006696

#TimeUsernameProblemLanguageResultExecution timeMemory
1006696ereringLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pb push_back #define ll long long #define int long long const long long inf=1e18; const int MOD=998244353; const int N=(1<<8); int bitcount[N],best[N],id[N]; signed main() { // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; int a[n],k[n],sol[n],par[n]; for(int i=0;i<n;i++)cin>>a[i]; for(int i=0;i<(1<<8);i++){ int x=i; while(x>0){ if(x%2==1)bitcount[i]++; x/=2; } best[i]=0; id[i]=0; } int ans=0,idx=0; for(int i=0;i<n;i++){ cin>>k[i]; sol[i]=1; par[i]=i; for(int j=0;j<(1<<8);j++){ // if(i==3 && j==3)cout<<(a[i]&j)<<' '<<k[i]<<' '<<best[j]+1<<endl; if(bitcount[(a[i]&j)]==k[i] && best[j]+1>sol[i]){ sol[i]=best[j]+1; par[i]=id[j]; } } if(sol[i]>best[a[i]]){ best[a[i]]=sol[i]; id[a[i]]=i; } if(ans<sol[i]){ ans=sol[i]; idx=i; } } cout<<ans<<endl; vector<int> v; while(1){ int x=idx; v.pb(x+1); idx=par[idx]; if(idx==x)break; } for(int i=v.size()-1;i>=0;i--)cout<<v[i]<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...