# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697031 | allllekssssa | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 6029 ms | 4216 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;
#define pii pair<int, int>
#define pb push_back
const int maxN = 1e6 + 10;
int a[maxN], k[maxN];
int n;
map<int, pii> dp[21];
int rz[maxN], pre[maxN];
int main() {
cin >> n;
for (int i = 1; i<=n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i<=n; i++) {
scanf("%d", &k[i]);
}
int ans = 0;
for (int i = 1; i<=n; i++) {
int best = 0;
int idx = 0;
int currentBitCnt = __builtin_popcount(a[i]);
for (int bCnt = k[i]; bCnt <= 20; bCnt++) {
int minPresek = bCnt + currentBitCnt - 20;
if (minPresek > k[i]) continue;
for (auto j: dp[bCnt]) {
if (__builtin_popcount(a[i] & j.first) == k[i]) {
if (j.second.first > best) {
best = j.second.first;
idx = j.second.second;
}
}
}
}
if (dp[currentBitCnt][a[i]].first < best + 1) {
dp[currentBitCnt][a[i]] = {best + 1, i};
rz[i] = best + 1;
pre[i] = idx;
}
if (rz[i] > rz[ans]) ans = i;
}
cout << rz[ans] << endl;
vector<int> indices;
while(rz[ans] != 0) {
indices.pb(ans);
ans = pre[ans];
}
reverse(indices.begin(), indices.end());
for (auto i: indices) {
printf("%d ", i);
}
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... |