이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the Name of God
#include <bits/stdc++.h>
using namespace std;
#define	ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = b; i >= a; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 1e5 + 5;
const int mod = 1e8 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;
int n, a[N], k[N], id, dpn[N], p[N];
pair<int, int> dp[N];
vector<int> ans;
int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	rep(i, 1, n)
        cin >> a[i];
    rep(i, 1, n)
        cin >> k[i];
    if (n > 5000) {
        rep(i, 1, n) {
            pair<int, int> cur = mp(1, i);
            rep(last, 0, 255)
                if (bpc(a[i] & last) == k[i] && dp[last].fi >= cur.fi)
                        p[i] = dp[last].se, cur = mp(dp[last].fi + 1, i);
            dp[a[i]] = max(dp[a[i]], cur);
            if (dp[a[i]] > dp[a[id]])
                id = i;
        }
    }
    else {
        rep(i, 1, n) {
            dpn[i] = 1;
            rep(j, 1, i - 1)
                if (bpc(a[i] & a[j]) == k[i] && dpn[j] >= dpn[i])
                    p[i] = j, dpn[i] = dpn[j] + 1;
            if (dpn[i] > dpn[id])
                id = i;
        }
    }
    while (id >= 1) {
        ans.pb(id);
        id = p[id];
    }
    cout << sz(ans) << "\n";
    per(i, 0, sz(ans) - 1)
        cout << ans[i] << ' ';
	#ifdef Madi
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
	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... |