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 = 10;
int n,a[N] , k[N];
int dp[1<<10][1<<10][M] , p[1<<10][1<<10][M], P[N] , mx , id;
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i= 0; i< n; ++i) cin >> a[i];
for(int i = 0; i< n; ++i)cin >> k[i];
memset(P , -1 , sizeof(P));
for(int i =0; i < n; ++i){
int A = a[i] >> M , B = a[i] & ((1<<M) - 1) , ans = 0;
for(int l =0; l < (1<<M); ++l){
int y = k[i] - __builtin_popcount(l & A);
if(y < 0 || y > 10) continue;
if(dp[l][B][y] > ans){
ans = dp[l][B][y];
P[i] = p[l][B][y];
}
}
ans++;
if(ans > mx)mx = ans, id = i;
for(int r= 0; r< (1<<M);++r){
int y = __builtin_popcount(B & r);
if(dp[A][r][y] < ans){
dp[A][r][y] = ans;
p[A][r][y] = i;
}
}
}
vector<int> X;
while(1){
X.emplace_back(id);
id = P[id];
if(id == -1)break;
}
reverse(X.begin() , X.end());
cout << X.size() << endl;
for(int x : X)cout << x+1 << " ";
}
# | 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... |