# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241837 | ChrisT | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 4681 ms | 93688 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;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e5+5, MOD = 1e9+7, BASE = 31, MASK = (1 << 10) - 1;
pii idk[1 << 10][1 << 10][11];
int a[MN], k[MN], dp[MN], from[MN];
int main () {
int n;
scanf ("%d",&n);
for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
for (int i = 1; i <= n; i++) scanf ("%d",&k[i]);
int ret = 0, wot = 0;
for (int i = 1; i <= n; i++) {
dp[i] = 1; from[i] = -1;
for (int m1 = 0; m1 < (1 << 10); m1++) {
int need = k[i] - __builtin_popcount((a[i]>>10)&m1);
if (need < 0 || need > 10) continue;
pii &go = idk[m1][a[i]&MASK][need];
if (go.first + 1 > dp[i]) {
dp[i] = go.first + 1;
from[i] = go.second;
}
}
for (int m2 = 0; m2 < (1 << 10); m2++) {
pii &go = idk[a[i]>>10][m2][__builtin_popcount(a[i]&m2)];
if (dp[i] > go.first) {
go.first = dp[i];
go.second = i;
}
}
if (dp[i] > ret) {
ret = dp[i];
wot = i;
}
}
vector<int> print;
do {
print.push_back(wot);
} while (~(wot = from[wot]));
reverse(all(print));
printf ("%d\n",ret);
for (int i : print) 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... |