제출 #967223

#제출 시각아이디문제언어결과실행 시간메모리
967223AlphaMale06Longest beautiful sequence (IZhO17_subsequence)C++17
7 / 100
138 ms62608 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+3; const int bits=10; const int mask = 1<<bits; int dp[bits+1][mask][mask], prv[N], from[bits][mask][mask], cnt[mask], a[N], b[N], l[N], r[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); for(int i=0; i<mask; i++)cnt[i]=__builtin_popcount(i); int n; cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; l[i]=a[i]>>10; r[i]=a[i]&((1<<10)-1); } for(int i=1; i<=n; i++)cin >> b[i]; int mxans=0, mxst=0; for(int i=1; i<=n; i++){ int mx=0; for(int j=0; j<mask; j++){ int share = cnt[j&r[i]]; if(b[i]-share>=0 && b[i]-share<=10){ mx=max(mx, dp[b[i]-share][l[i]][j]); if(mx==dp[b[i]-share][l[i]][j])prv[i]=from[b[i]-share][l[i]][j]; } } mx++; for(int j=0; j<mask; j++){ dp[cnt[j&l[i]]][j][r[i]]=max(dp[cnt[j&l[i]]][j][r[i]], mx); if(dp[cnt[j&l[i]]][j][r[i]]==mx)from[cnt[j&l[i]]][j][r[i]] = i; } if(mx>mxans){ mxans=mx; mxst = i; } } cout << mxans << '\n'; vector<int> cons; while(mxst!=0){ cons.push_back(mxst); mxst=prv[mxst]; } 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...