# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36180 | UncleGrandpa925 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 4549 ms | 48776 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.
/*input
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 100005
#define M 1024
#define bit(x,y) ((x>>y)&1LL)
int n;
int a[N], b[N], cnt[M];
int dp[N], par[N];
int g[M][M][11];
vector<int> order;
signed main() {
// #ifdef in1code
// freopen("1test.inp", "r", stdin);
// #endif
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
for (int i = 0; i < M; i++) cnt[i] = __builtin_popcount(i);
memset(g, 0, sizeof(g));
pair<int, int> ans = mp(1, 1);
for (int i = 1; i <= n; i ++) {
dp[i] = 1;
int prefix = a[i] >> 10;
int suffix = a[i] - (prefix << 10);
for (int mask = 0; mask < M; mask++) {
int left = b[i] - cnt[mask & prefix];
if (left < 0 || left > 10) continue;
int y = g[mask][suffix][left];
if (dp[y] + 1 > dp[i]) {
dp[i] = dp[y] + 1; par[i] = y;
}
}
if (dp[i] > ans.fi)
ans = mp(dp[i], i);
for (int mask = 0; mask < M; mask ++) {
int x = mask & suffix; int &y = g[prefix][mask][cnt[x]];
if (dp[y] < dp[i])
y = i;
}
}
while (ans.fi > 0) {
order.push_back(ans.se);
ans.se = par[ans.se]; ans.fi--;
}
reverse(order.begin(), order.end());
printf("%lu\n", order.size());
for (int i = 0; i < order.size(); i++) printf("%d ", order[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... |