Submission #1098800

#TimeUsernameProblemLanguageResultExecution timeMemory
1098800giaminh2211Longest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
2727 ms109664 KiB
#include <bits/stdc++.h> #define fi first #define se second using namespace std; using ll=long long; using pii=pair<int, int>; const int N=1e5+13; int n; int a[N]; int k[N]; int dp[N]; pii sus[1024][1024][13]; int res; int tr[N]; vector<int> v; void scan(){ cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; } for(int i=1; i<=n; i++){ cin >> k[i]; } } void solve(){ for(int i=1; i<=n; i++){ pii pep=make_pair(0, 0); for(int pre=0; pre < 1024; pre++){ int z=__builtin_popcount(pre & (a[i] & 1023)); int cc=k[i]-z; if(cc < 0 || cc >= 10) continue; pep=max(pep, sus[pre][a[i] >> 10][cc]); } dp[i]=pep.fi+1; tr[i]=pep.se; for(int suf=0; suf < 1024; suf++){ assert(__builtin_popcount(suf & (a[i] >> 10)) <= 10); sus[a[i] & 1023][suf][__builtin_popcount(suf & (a[i] >> 10))]=max(sus[a[i] & 1023][suf][__builtin_popcount(suf & (a[i] >> 10))], make_pair(dp[i], i)); } } auto sus=max_element(dp+1, dp+n+1); cout << *sus << '\n'; int id=sus-dp; while(id!=0){ v.push_back(id); id=tr[id]; } reverse(begin(v), end(v)); for(int c: v) cout << c << ' '; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); scan(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...