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;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n;
pii best = {1, 0};
cin >> n;
vi a(n), k(n);
for(int &i : a)
cin >> i;
for(int &i : k)
cin >> i;
vi prev(n), dp(n, 1), ans;
iota(prev.begin(), prev.end(), 0);
for(int i = 1; i < n; i++){
for(int j = 0; j < i; j++){
if(__builtin_popcount(a[j] & a[i]) == k[i] && dp[j] + 1 > dp[i]){
dp[i] = dp[j] + 1;
prev[i] = j;
if(dp[i] > best.fi)
best = {dp[i], i};
}
}
}
while(prev[best.se] != best.se){
ans.emplace_back(best.se + 1);
best.se = prev[best.se];
}
ans.emplace_back(best.se + 1);
reverse(ans.begin(), ans.end());
cout << best.fi << "\n";
for(int i : ans){
cout << i << " ";
}
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... |