Submission #936110

#TimeUsernameProblemLanguageResultExecution timeMemory
93611012345678Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
2 ms4700 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, v[nx], k[nx]; pair<int, int> t, vl[nx], dp[nx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>v[i], dp[i]={1, i}; for (int i=1; i<=n; i++) cin>>k[i]; for (int i=0; i<512; i++) vl[i]={-1, -1}; for (int i=1; i<=n; i++) { for (int j=0; j<512; j++) { if (vl[j].first==-1) continue; if (__builtin_popcount(v[i]&j)==k[i]) dp[i]=max(dp[i], {vl[j].first+1, vl[j].second}); } vl[v[i]]=max(vl[v[i]], {dp[i].first, i}); t=max(t, {dp[i].first, i}); } cout<<t.first<<'\n'; vector<int> res; while (dp[t.second].second!=t.second) res.push_back(t.second), t.second=dp[t.second].second; res.push_back(t.second); reverse(res.begin(), res.end()); for (auto x:res) cout<<x<<' '; } /* 4 1 2 3 4 10 0 1 0 5 5 3 5 3 5 10 1 20 1 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...