# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
263134 | ttnhuy313 | Longest beautiful sequence (IZhO17_subsequence) | C++14 | 0 ms | 0 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.
#define N 1000001
using namespace std;
typedef long long ll;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
int d[1 << 10][1 << 10][11], p[1 << 10][1 << 10][11], pc[1 << 20];
int a[N], k[N], n, bm = (1 << 10) - 1, ans, par[N], ind;
int main () {
cin >> n;
for (int i = 0; i < (1 << 10); i++)
pc[i] = __builtin_popcount (i);
memset (p, -1, sizeof (p));
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> k[i];
}
for (int i = 0; i < n; i++) {
int x = 0;
par[i] = -1;
for (int j = 0; j < (1 << 10); j++) {
int l = k[i] - pc[j & (a[i] >> 10)];
if (l < 0 || l > 10) continue;
if (x < d[j][a[i] & bm][l]) {
par[i] = p[j][a[i] & bm][l];
x = d[j][a[i] & bm][l];
}
}
x++;
for (int j = 0; j < (1 << 10); j++) {
int& c = d[a[i] >> 10][j][pc[j & a[i]]];
if (x > c) {
c = x;
p[a[i] >> 10][j][pc[j & a[i]]] = i;
}
}
if (x > ans) {
ans = x;
ind = i;
}
}
vector <int> v;
cout << ans << endl;
while (ind != -1) {
v.push_back (ind + 1);
ind = par[ind];
}
reverse (v.begin(), v.end());
for (int i : v)
cout << i << ' ';
}