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 ll = long long;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
const int N = 1e5 + 5;
int n;
int a[N];
int k[N];
int p[N];
int dp[N];
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> k[i];
}
fill(dp + 1, dp + n + 1, 1);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
if(__builtin_popcount(a[i] & a[j]) == k[i]){
if(ckmax(dp[i], dp[j] + 1)){
p[i] = j;
}
}
}
}
int ans = 0, curr = 0;
for(int i = 1; i <= n; i++){
if(ckmax(ans, dp[i])){
curr = i;
}
}
cout << ans << '\n';
vector<int> ret;
while(curr){
ret.push_back(curr);
curr = p[curr];
}
reverse(ret.begin(), ret.end());
for(auto x : ret) 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... |