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;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const int B = 10;
struct DS {
pi best[1<<B][1<<B][B*2+1] = {};
static void cmax(pi& a, const pi& b) {
a = max(a,b);
}
DS() {}
static pi split(int a) {
return {a&((1<<B)-1),a>>B};
}
void insert(int a, pi v) {
auto [l,r] = split(a);
for(int msk=0;msk<1<<B;++msk) {
cmax(best[msk][r][__builtin_popcount(msk&a)],v);
}
}
pi query(int a, int k) {
auto [l,r] = split(a);
pi res = {};
for(int msk=0;msk<1<<B;++msk) {
int pp = __builtin_popcount(msk&r);
if(pp<=k) {
cmax(res,best[l][msk][k-pp]);
}
}
return res;
}
} *ds = new DS();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vi a(n);
vector<short> k(n);
for(auto& i : a) cin >> i;
for(auto& i : k) cin >> i;
vi dp(n),par(n,-1);
for(int i=0;i<n;++i) {
auto [v,pr] = ds->query(a[i],k[i]);
if(v) par[i]=pr;
dp[i]=v+1;
ds->insert(a[i],{dp[i],i});
}
// recover solution
auto it = max_element(all(dp));
int i = it-dp.begin();
cout << *it << '\n';
vi b;
while(i!=-1) {
b.push_back(i+1);
i=par[i];
}
reverse(all(b));
cout << b << '\n';
}
# | 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... |