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 ;
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
int n ; cin >> n ;
vector<int> a(n), k(n) ;
for (int i = 0 ; i < n ; i++) cin >> a[i] ;
for (int i = 0 ; i < n ; i++) cin >> k[i] ;
vector<ll> dp(n, 1) , pr(n, -1) ;
set<pair<int,int>> bit[35] ;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < 31 ; j++) {
if (bit[j].empty()) continue ;
auto [DP, l] = *bit[j].rbegin() ;
if (__builtin_popcount(a[l] & a[i]) == k[i] && dp[i] < DP + 1) {
dp[i] = DP + 1 ;
pr[i] = l ;
}
}
int cnt = __builtin_popcount(a[i]) ;
bit[cnt].insert({dp[i], i}) ;
}
int pos = max_element(dp.begin(), dp.end()) - dp.begin() ;
cout << dp[pos] << "\n" ;
vector<int> res ;
while (pos != -1) {
res.push_back(pos) ;
pos = pr[pos] ;
}
reverse(res.begin(), res.end()) ;
for (int i : res) cout << i + 1 << ' ' ;
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... |