제출 #964852

#제출 시각아이디문제언어결과실행 시간메모리
964852AlphaMale06Longest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
315 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+3; const int bits=9; int dp[1<<bits], prv[1<<bits], from[1<<bits], a[N], b[N]; int main() { int n; cin >> n; for(int i=1; i<= n; i++)cin >> a[i]; for(int i=1; i<= n; i++)cin >> b[i]; for(int i=1; i<=n; i++){ int val=1; int mxind=0; for(int j=0; j<(1<<bits); j++){ if(__builtin_popcount(j&a[i])==b[i]){ if(dp[j]+1>=val){ val=dp[j]+1; mxind=from[j]; } } } if(val>dp[a[i]]){ from[a[i]]=i; dp[a[i]]=val; prv[a[i]]=mxind; } } int ans=0, cur=0; for(int i=0; i<(1<<bits); i++){ if(dp[i]>ans){ ans=dp[i]; cur=from[i]; } } cout << ans << '\n'; vector<int> cons; while(cur!=0){ cons.push_back(cur); cur=prv[a[cur]]; } reverse(cons.begin(), cons.end()); for(int e : cons)cout << e << " "; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...