# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55390 | BThero | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 3767 ms | 85920 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.
// Why I am so dumb? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 1e5+5;
const int M = 1024;
int d[11][M][M];
int need[MAXN];
int arr[MAXN];
int par[MAXN];
int dp[MAXN];
int bp[M];
int n;
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
}
for (int i = 1; i <= n; ++i) {
scanf("%d", &need[i]);
}
for (int i = 0; i < M; ++i) {
bp[i] = __builtin_popcount(i);
}
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
int lc = (arr[i] >> 10), rc = arr[i] - (lc << 10);
for (int lp = 0; lp < M; ++lp) {
int k = need[i] - bp[lc & lp];
if (k < 0 || k > 10) {
continue;
}
int id = d[k][lp][rc];
if (dp[id] + 1 > dp[i]) {
dp[i] = dp[id] + 1;
par[i] = id;
}
}
for (int rn = 0; rn < M; ++rn) {
int k = bp[rc & rn];
int &id = d[k][lc][rn];
if (dp[i] > dp[id]) {
id = i;
}
}
}
int mx = 1;
for (int i = 2; i <= n; ++i) {
if (dp[i] > dp[mx]) {
mx = i;
}
}
vector<int> vv;
for (int x = mx; x; x = par[x]) {
vv.pb(x);
}
reverse(all(vv));
printf("%d\n", vv.size());
for (int it : vv) {
printf("%d ", it);
}
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
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... |