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 <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <random>
#include <chrono>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld double
#define pild pair<double,double>
using namespace std;
const ll N = 1E5 + 11;
const ll M = 10;
mt19937_64 bruh(chrono::steady_clock::now().time_since_epoch().count());
ll n, a[N], b[N], pd[N], rd[N];
int dp[1040][1040][11];
int cnt[N];
int main() {
speed;
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n; i++)
cin >> b[i];
for(int i = 1; i < (1<<(M + 1)); i++)
cnt[i] = __builtin_popcount(i);
ll lst = 0;
for(int i = 1; i <= n; i++) {
int z1 = a[i] >> M;
int z2 = a[i] - (z1<<M);
pd[i] = 1;
for(int j = 0; j < (1<<M); j++) {
int k = b[i] - cnt[(j&z2)];
if(k < 0 || k > b[i] || k > 10)continue;
if(pd[i] < pd[dp[j][z1][k]] + 1)
pd[i] = pd[dp[j][z1][k]] + 1, rd[i] = dp[j][z1][k];
}
for(int j = 0; j < (1<<M); j++) {
if(pd[i] > pd[dp[z2][j][cnt[z1&j]]])
dp[z2][j][cnt[z1&j]] = i;
}
if(pd[lst] < pd[i])
lst = i;
}
cout << pd[lst] << '\n';
vector<int> answ;
while(lst) {
answ.pb(lst);
lst = rd[lst];
}
reverse(all(answ));
for(int i = 0; i < answ.size(); i++)
cout << answ[i] << " ";
}
/*
1 2 3 4 5 6
*/
Compilation message (stderr)
subsequence.cpp: In function 'int main()':
subsequence.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < answ.size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |