# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956092 | Trisanu_Das | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 6048 ms | 2396 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
pair<int, int> ans;
vector<int> a(n), b(n), dp(n), par(n, -1);
for(int &p : a) cin >> p;
for(int &p : b) cin >> p;
for(int i=0; i<n; i++) {
for(int j=0; j<i; j++) if(__builtin_popcount(a[i]&a[j])==b[i]) if(dp[j]>dp[i]) dp[i]=dp[j], par[i]=j;
ans=max(ans, {++dp[i], i});
}
deque<int> lbs;
cout << ans.first << '\n';
int idx=ans.second;
while(idx!=-1) {
lbs.push_front(idx);
idx=par[idx];
}
for(int p : lbs) cout << p+1 << ' '; cout << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |