# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
519168 | nickmet2004 | Longest beautiful sequence (IZhO17_subsequence) | C++11 | 0 ms | 0 KiB |
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+5][1<<10+5][M+1] , p[1<<10+5][1<<10+5][M+1], 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 << " ";
}