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;
const int maxn=1e5+5;
const int B = (1<<10);
int n,k[maxn],a[maxn],p[B],pos;
pair<int,int>dp[maxn],jog[B][B][11];
vector<int>v;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
for(int i = 0;i < B;i++) p[i] = __builtin_popcount(i);
memset(jog,-1,sizeof(jog));
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= n;i++) cin >> k[i];
for(int i = 1;i <= n;i++){
int lf = (a[i]>>10);
int rg = a[i] - (lf<<10);
dp[i] = {1,-1};
for(int j = 0;j < B;j++){
int lp = p[j & lf];
if(lp <= k[i] and lp+10 >= k[i] and jog[j][rg][k[i]-lp].first + 1 > dp[i].first){
dp[i] = jog[j][rg][k[i]-lp];
dp[i].first++;
}
}
if(dp[pos].first < dp[i].first) pos = i;
for(int j = 0;j < B;j++){
int lp = p[rg & j];
if(jog[lf][j][lp].first < dp[i].first) jog[lf][j][lp] = {dp[i].first,i};
}
}
cout<<dp[pos].first<<'\n';
while(pos != -1){
v.push_back(pos);
pos = dp[pos].second;
}
reverse(v.begin(),v.end());
for(auto i : v) cout<<i<<' ';
}
/*
4
1 2 3 4
10 0 1 0
2
8 9
20 0
5
5 3 5 3 5
10 1 20 1 20
*/
# | 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... |