| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 96152 | choikiwon | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 404 ms | 167672 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;
typedef pair<int, int> pii;
const int MN = 100010;
int bcnt[1 << 20];
int N;
int A[MN], B[MN], pre[MN];
pii cnt[1 << 10][1 << 10][20];
void add(int v, int t, int id) {
    int a = v % (1 << 10);
    int b = v / (1 << 10);
    for(int i = 0; i < (1 << 10); i++) {
        cnt[a][i][ bcnt[b & i] ] = max(cnt[a][i][ bcnt[b & i] ], pii(t, id));
    }
}
int main() {
    for(int i = 1; i < (1 << 20); i++) {
        for(int j = 0; j < 20; j++) {
            if(i & (1 << j)) bcnt[i]++;
        }
    }
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
    }
    int ans = 0, la = -1;
    for(int i = 0; i < N; i++) {
        int t = 0, p = -1;
        for(int j = 0; j < (1 << 10); j++) {
            int r = B[i] - bcnt[ A[i] & j ];
            if(r < 0) continue;
            pii d = cnt[j][ A[i] / (1 << 10) ][r];
            if(t < d.first + 1) {
                t = d.first + 1;
                p = d.second;
            }
        }
        add(A[i], t, i);
        pre[i] = p;
        if(ans < t) {
            ans = t;
            la = i;
        }
    }
    printf("%d\n", ans);
    vector<int> sol;
    for(int i = 0; i < ans; i++) {
        sol.push_back(la);
        la = pre[la];
    }
    for(int i = (int)sol.size() - 1; i >= 0; i--) {
        printf("%d ", sol[i] + 1);
    }
}
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... | ||||
