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;
const int N = 1e5+3;
const int bits=10;
const int mask = 1<<bits;
int dp[bits+1][mask][mask], prv[N], from[bits][mask][mask], cnt[mask], a[N], b[N], l[N], r[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i=0; i<mask; i++)cnt[i]=__builtin_popcount(i);
int n;
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i];
l[i]=a[i]>>10;
r[i]=a[i]&((1<<10)-1);
}
for(int i=1; i<=n; i++)cin >> b[i];
int mxans=0, mxst=0;
for(int i=1; i<=n; i++){
int mx=0;
for(int j=0; j<mask; j++){
int share = cnt[j&r[i]];
if(b[i]-share>=0 && b[i]-share<=10){
mx=max(mx, dp[b[i]-share][l[i]][j]);
if(mx==dp[b[i]-share][l[i]][j])prv[i]=from[b[i]-share][l[i]][j];
}
}
mx++;
for(int j=0; j<mask; j++){
dp[cnt[j&l[i]]][j][r[i]]=max(dp[cnt[j&l[i]]][j][r[i]], mx);
if(dp[cnt[j&l[i]]][j][r[i]]==mx)from[cnt[j&l[i]]][j][r[i]] = i;
}
if(mx>mxans){
mxans=mx;
mxst = i;
}
}
cout << mxans << '\n';
vector<int> cons;
while(mxst!=0){
cons.push_back(mxst);
mxst=prv[mxst];
}
reverse(cons.begin(), cons.end());
for(int e : cons)cout << e << " ";
cout << '\n';
}
# | 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... |