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;
typedef pair<int,int> pii;
int n,a[100001],b[100001],Ans,node[100001],mv;
pii dp[1<<10][1<<10][21]; //pii(val,index);
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n;
for (int i=1; i<=n; ++i) cin>>a[i];
for (int i=1; i<=n; ++i) cin>>b[i];
for (int i=1; i<=n; ++i) {
int ans=1;
int fir=a[i]>>10, sec=a[i]%(1<<10);
node[i]=i;
for (int mask=0; mask<(1<<10); ++mask) {
int cnt=__builtin_popcount((mask>>10)&fir);
int want=b[i]-cnt;
if (want>=0) {
if (ans<dp[mask][sec][want].first+1) {
ans=dp[mask][sec][want].first+1;
node[i]=dp[mask][sec][want].second;
}
}
}
for (int mask=0; mask<(1<<10); ++mask) {
int cnt=__builtin_popcount(sec&mask);
if (ans>dp[fir][mask][cnt].first) {
dp[fir][mask][cnt].first=ans;
dp[fir][mask][cnt].second=i;
}
}
if (ans>Ans) {
Ans=ans;
mv=i;
}
}
cout<<Ans<<"\n";
vector<int> temp;
while (Ans--) {
temp.push_back(mv);
mv=node[mv];
}
reverse(temp.begin(),temp.end());
for (auto s : temp) cout<<s<<" ";
}
# | 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... |