# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36120 | aome | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 29 ms | 93852 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 N = 100005;
const int M = 1024;
const int INF = 1e9;
int n, a[N], b[N], cnt[M];
pair<int, int> f[N];
pair<int, int> g[M][M][11];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
for (int i = 0; i < M; ++i) {
for (int j = 0; j < 10; ++j) cnt[i] += i >> j & 1;
}
for (int i = 0; i < M; ++i) for (int j = 0; j < M; ++j) {
for (int k = 0; k < 10; ++k) {
g[i][j][k] = make_pair(-INF, 0);
}
}
int pos = 0;
for (int i = 1; i <= n; ++i) {
int pre = 0, suf = 0;
for (int j = 0; j < 10; ++j) {
if (a[i] >> j & 1) pre |= 1 << j;
}
for (int j = 10; j < 20; ++j) {
if (a[i] >> j & 1) suf |= 1 << (j - 10);
}
f[i] = make_pair(1, 0);
for (int j = 0; j < M; ++j) {
int tmp = j & pre;
if (cnt[tmp] > b[i]) continue;
f[i] = max(f[i], g[j][suf][b[i] - cnt[tmp]]);
}
for (int j = 0; j < M; ++j) {
int tmp = suf & j;
g[pre][j][cnt[tmp]] = max(g[pre][j][cnt[tmp]], make_pair(f[i].first + 1, i));
}
if (f[pos].first < f[i].first) pos = i;
}
vector<int> res;
int cur = pos;
while (cur) {
res.push_back(cur), cur = f[cur].second;
}
reverse(res.begin(), res.end());
printf("%d\n", res.size());
for (int i = 0; i < res.size(); ++i) printf("%d ", res[i]);
}
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... |