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 + 5, M = (1 << 20), K = (1 << 10);
int n, a[N], k[N], cnt[M], pr[N];
int dp[K][11][K], pos[K][11][K];
int ans, ans_pos;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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 = 0; i < M; i++){
cnt[i] = __builtin_popcount(i);
}
for(int i = 1; i <= n; i++){
int mask1 = (a[i] >> 10),
mask2 = (a[i] & (K - 1));
int cur = 0, cur_pos = 0;
for(int mask = 0; mask < K; mask++){
int need = k[i] - cnt[(mask1 & mask)];
if(0 <= need && need <= 10){
if(dp[mask][need][mask2] > cur){
cur = dp[mask][need][mask2];
cur_pos = pos[mask][need][mask2];
}
}
}
cur += 1;
if(cur > ans){
ans = cur;
ans_pos = i;
}
pr[i] = cur_pos;
for(int mask = 0; mask < K; mask++){
int dif = cnt[(mask2 & mask)];
if(dp[mask1][dif][mask] < cur){
dp[mask1][dif][mask] = cur;
pos[mask1][dif][mask] = i;
}
}
}
vector < int > anss;
while(ans_pos > 0){
anss.push_back(ans_pos);
ans_pos = pr[ans_pos];
}
reverse(anss.begin(), anss.end());
cout << (int)anss.size() << "\n";
for(auto it : anss){
cout << it << " ";
}
}
# | 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... |