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>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const int M = 8;
signed main() {
int n, id = 1;
cin >> n;
vector<int> a(n+1), k(n+1), prv(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++) cin >> k[i];
vector<pair<int, int> > dp(1 << M);
for(int i=1; i<=n; i++) {
dp[a[i]] = max(dp[a[i]], { 1, i });
for(int j=0; j<(1<<M); j++) {
if(__builtin_popcount(a[i] & j) == k[i]) {
if(dp[a[i]].first < dp[j].first + 1) {
dp[a[i]].first = dp[j].first + 1;
dp[a[i]].second = i;
prv[i] = dp[j].second;
if(dp[a[i]].first > dp[a[id]].first) id = i;
}
}
}
}
cout << dp[a[id]].first << '\n';
vector<int> ans;
while(id) {
ans.push_back(id);
id = prv[id];
}
reverse(ans.begin(), ans.end());
for(int &x : ans) cout << x << " ";
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... |