이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
int n;
int a[MAXN+1], k[MAXN+1];
void subtask1and2() {
    int dp[n+1] = {}, pre[n+1];
    for (int i = 1; i <= n; i++) {
        dp[i] = 1;
        pre[i] = i;
        for (int j = 1; j < i; j++) if (__builtin_popcount(a[i] & a[j]) == k[i]) {
                if (dp[j] + 1 > dp[i]) {
                    dp[i] = dp[j] + 1;
                    pre[i] = j;
                }
            }
    }
    int final = max_element(dp, dp+n+1) - dp;
    vector<int> ans;
    while (pre[final] != final) {
        ans.push_back(final);
        final = pre[final];
    }
    ans.push_back(final);
    reverse(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << " ";
}
void subtask3() {
    int dp[n+1] = {}, pre[n+1];
    int best[256] = {}, bestindex[256] = {};
    for (int i = 1; i <= n; i++) {
        dp[i] = 1;
        pre[i] = i;
        for (int val = 0; val < 256; val++) {
            if (__builtin_popcount(a[i] & val) != k[i]) continue;
            if (best[val] + 1 > dp[i]) {
                dp[i] = best[val] + 1;
                pre[i] = bestindex[val];
            }
        }
        if (dp[i] > best[a[i]]) {
            best[a[i]] = dp[i];
            bestindex[a[i]] = i;
        }
    }
    int final = max_element(dp, dp+n+1) - dp;
    vector<int> ans;
    while (pre[final] != final) {
        ans.push_back(final);
        final = pre[final];
    }
    ans.push_back(final);
    reverse(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << " ";
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> k[i];
    if (*max_element(a, a+n+1) < 256) {
        subtask3();
    } else {
        subtask1and2();
    }
}
| # | 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... |