제출 #866670

#제출 시각아이디문제언어결과실행 시간메모리
866670Dec0DeddLongest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
6011 ms175136 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int N = 1e5+10; const int K = 1024; const int X = 10; int p[N], a[N], x[N], n; pii dp[K][K][2*X+1]; int main() { cin>>n; for (int i=1; i<=n; ++i) cin>>a[i]; for (int i=1; i<=n; ++i) cin>>x[i]; pii ans={1, 1}; for (int i=1; i<=n; ++i) { int lf=a[i]&((1<<X)-1), rf=((a[i]>>X)&((1<<X)-1)); pii mx={0, 0}; for (int lms=0; lms<K; ++lms) { int v=x[i]-__builtin_popcount(lms&lf); if (v < 0) continue; mx=max(mx, dp[lms][rf][v]); } p[i]=mx.second; for (int rms=0; rms<K; ++rms) { int v=__builtin_popcount(rms&rf); dp[lf][rms][v]=max(dp[lf][rms][v], {mx.first+1, i}); } ans=max(ans, {mx.first+1, i}); } vector<int> v; int g=ans.second; while (g != 0) v.push_back(g), g=p[g]; reverse(v.begin(), v.end()); for (int i=1; i<ans.first; ++i) { assert(__builtin_popcount(a[v[i]]&a[v[i-1]]) == x[v[i]]); } assert((int)v.size() == ans.first); cout<<ans.first<<"\n"; for (auto u : v) cout<<u<<" "; 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...