제출 #964793

#제출 시각아이디문제언어결과실행 시간메모리
964793AlphaMale06Longest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
6034 ms2444 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+3; int dp[N], prv[N], 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]; int ans=0, cur=0; for(int i=1; i<=n; i++){ dp[i]=1; prv[i]=0; for(int j=i-1; j>=1; j--){ if(__builtin_popcount(a[j]&a[i])==b[i]){ if(dp[j]+1>dp[i]){ dp[i]=dp[j]+1; prv[i]=j; } } } ans=max(ans, dp[i]); if(dp[i]==ans)cur=i; } cout << ans << '\n'; vector<int> cons; while(cur!=0){ cons.push_back(cur); cur=prv[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...