이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n;
int a[N], b[N];
int dp[N], w[N];
int B[N];
int D[N], d[N];
vector < int > V;
int main()
{
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    for (int i = 1; i <= n; i++)
        cin>>b[i];
    B[0] = 0;
    for (int i = 1; i < (1<<20); i++)
        B[i] = 1 + B[(i & (i - 1))];
    for (int i = 1; i <= n; i++){
        if (n <= 5000){
            for (int j = 1; j < i; j++)
                if (B[(a[i] & a[j])] == b[i])
                    if (dp[i] < dp[j]){
                        dp[i] = dp[j];
                        w[i] = j;
                    }
        }
        for (int j = 0; j < (1<<8); j++)
            if (B[(a[i] & j)] == b[i])
                if (dp[i] < D[j]){
                    dp[i] = D[j];
                    w[i] = d[j];
                }
        dp[i]++;
        if (D[a[i]] < dp[i]){
            D[a[i]] = dp[i];
            d[a[i]] = i;
        }
    }
    int x = 1;
    for (int i = 2; i <= n; i++)
        if (dp[i] > dp[x])
            x = i;
    cout<<dp[x]<<endl;
    while (x){
        V.push_back(x);
        x = w[x];
    }
    for (int i = (int)V.size() - 1; i >= 0; i--)
        cout<<V[i]<<" ";
    cout<<endl;
    return 0;
}
| # | 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... |