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>
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define epb emplace_back
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
int cnt[1025];
int dp[100001];
int dp2[100001];
int dp1[1025][1025][21];
void pre(){
for(int i=0;i<=1024;i++){
cnt[i]=__builtin_popcount(i);
}
}
int main(){
pre();
int n;cin>>n;
int a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
int k[n+1];
for(int i=1;i<=n;i++){
cin>>k[i];
}
for(int i=1;i<=n;i++){
int x=0,y=0;
y=a[i]%1024;
x=a[i]/1024;
for(int j=0;j<1024;j++){
int t=y&j;
t=cnt[t];
int v=dp1[j][x][k[i]-t];
if(dp[i]<dp[v]+1)dp[i]=dp[v]+1,dp2[i]=v;
}
for(int j=0;j<1024;j++){
int t=x&j;
t=cnt[t];
int v=dp1[y][j][t];
if(dp[i]>dp[v])dp1[y][j][t]=i;
}
}
int mx=-1;
int mxi;
for(int i=1;i<=n;i++){
if(dp[i]>mx)mx=dp[i],mxi=i;
}
vector<int>vec;
while(mxi){
vec.pb(mxi);
mxi=dp2[mxi];
}
cout<<vec.size()<<"\n";
reverse(vec.begin(),vec.end());
for(int to:vec){
cout<<to<<' ';
}
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... |