제출 #1006681

#제출 시각아이디문제언어결과실행 시간메모리
1006681ereringLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
49 ms8572 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<<20)+1; int bitcount[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<<20);i++){ int x=i; while(x>0){ if(x%2==1)bitcount[i]++; x/=2; } } int ans=0,idx=0; for(int i=0;i<n;i++){ cin>>k[i]; sol[i]=1; par[i]=i; for(int j=i-1;j>=0;j--){ if(bitcount[(a[i]&a[j])]==bitcount[k[i]]){ // cout<<a[i]<<" "<<a[j]<<" "<<k[i]<<" "<<(a[i]&a[j])<<endl; if(sol[j]+1>sol[i]){ sol[i]=sol[j]+1; par[i]=j; } } } 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...