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>
#define pb push_back
#define s second
#define f first
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define pii pair<int,int>
#define ll long long
using namespace std;
const int N = 1e5 + 3;
int a[N],k[N],last[N];
int d[1026][1026][12],id[1026][1026][12];
int blt[1026][1026];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
// freopen("subsequence.in", "r", stdin);
// freopen("subsequence.out", "w", stdout);
int n,ans = 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 x=0;x<1024;x++)
for (int y=0;y<1024;y++)
blt[x][y] = __builtin_popcount(x & y);
int idx = 0,x1,x2,c1,c2;
for (int i = 1; i <= n; i++){
x1 = x2 = 0;
int dp = 1;
for (int j = 0; j < 10; j++){
if (j < 10) x1 ^= (a[i] & (1<<j));
else x2 ^= (a[i] >> 10) & (1<<j);
}
for (int y1 = 0; y1 < 1024; y1++){
c2 = k[i] - blt[x1][y1];
if (c2 >= 0 && c2 <= 10) {
int nw = d[y1][x2][c2];
if (nw > dp){
dp = nw;
last[i] = id[y1][x2][c2];
}
}
}
//update
for (int y2 = 0; y2 < 1024; y2++){
c2 = blt[x2][y2];
if (d[x1][y2][c2] < dp + 1){
d[x1][y2][c2] = dp + 1;
id[x1][y2][c2] = i;
}
}
if (dp > ans){
ans = dp;
idx = i;
}
}
cout<<ans<<"\n";
vector <int> vec;
for (int i = 1; i <= ans; i++){
vec.pb(idx);
idx = last[idx];
}
for (int i = ans - 1; i >= 0;i--)
cout << vec[i] <<" ";
}
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:36:20: warning: unused variable 'c1' [-Wunused-variable]
36 | int idx = 0,x1,x2,c1,c2;
| ^~
# | 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... |