# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108839 | dubabuba | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 1 ms | 336 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;
const int mxn = 5050;
int a[mxn], dp[mxn];
int b[mxn], pr[mxn];
int n;
int main() {
// #ifndef LOCAL
freopen("subsequence.in", "r", stdin);
freopen("subsequence.out", "w", stdout);
// #endif
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++)
cin >> b[i];
int id = 1;
for(int i = 1; i <= n; i++) {
dp[i] = 1;
for(int j = 1; j < i; j++) {
int t = a[i] & a[j];
if(__builtin_popcount(t) != b[i])
continue;
if(dp[j] + 1 > dp[i]) {
dp[i] = dp[j] + 1;
pr[i] = j;
}
}
if(dp[id] < dp[i])
id = i;
}
vector<int> ind;
while(id) {
ind.push_back(id);
id = pr[id];
}
reverse(ind.begin(), ind.end());
// if(ind.size()) return 1;
cout << (int)ind.size() << endl;
for(int i : ind)
cout << i << ' ';
cout << endl;
return 0;
}
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... |