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;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define count(x) __builtin_popcount(x)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 1e5+5;
int n, a[N], k[N], par[N], dp[N];
int ddp[1024][1024][11];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>k[i];
}
memset(par, -1, sizeof(par));
for(int i=1;i<=n;i++){
int l = (a[i] >> 10);
int r = (a[i] & 1023);
int best = 0;
for(int j=0;j<1024;j++){
int tmp = count(j & r);
tmp = k[i] - tmp;
if(tmp < 0 || tmp > 10) continue;
if(dp[best] < dp[ddp[l][j][tmp]]) best = ddp[l][j][tmp];
}
dp[i] = dp[best]+1;
par[i] = best;
for(int j=0;j<1024;j++){
int tmp = count(j & l);
if(dp[i] > dp[ddp[j][r][tmp]]) ddp[j][r][tmp] = i;
}
}
int mx = 1;
for(int i=1;i <= n;i++){
if(dp[i] > dp[mx]) mx = i;
}
int start = mx;
vector<int>way;
while(start != 0){
way.pb(start);
start = par[start];
}
cout<<sz(way)<<"\n";
reverse(all(way));
for(auto x:way) cout<<x<<" ";
cout<<"\n";
return;
}
/*
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
*/
int main(){
fastios
int t = 1;
//cin>>t;
while(t--) solve();
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... |