# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798075 | PanosPask | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 6012 ms | 2360 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 N;
vector<int> dp;
vector<int> prv;
vector<int> a;
vector<int> k;
int main(void)
{
scanf("%d", &N);
a.resize(N);
k.resize(N);
for (int i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < N; i++) {
scanf("%d", &k[i]);
}
dp.resize(N);
prv.resize(N);
int maxv = 0, maxpos = 0;
for (int i = 0; i < N; i++) {
dp[i] = 0;
prv[i] = -1;
for (int j = i - 1; j >= 0; j--) {
if (__builtin_popcount(a[i] & a[j]) == k[i] && dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
prv[i] = j;
}
}
if (dp[i] > maxv) {
maxv = dp[i];
maxpos = i;
}
}
vector<int> ans;
for (int i = maxpos; i != -1; i = prv[i])
ans.push_back(i);
reverse(ans.begin(), ans.end());
printf("%d\n", (int)ans.size());
for (auto i : ans)
printf("%d ", i + 1);
printf("\n");
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... |