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>
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize ("-O3")
//#pragma GCC optimize ("Ofast")
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 100100;
//const int N2 = N * N;
const int PW = 8;
const int VL = (1 << PW);
const int oo = 2e9;
vector<int> vc;
int n, a[N], k[N], pr[N], f[N], ans = 0, nm = -1, ff[N], loc[N];
bool ok(int x, int y){
return (__builtin_popcount(a[x] & a[y]) == k[y]);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n;
bool okk = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
okk &= (a[i] < VL);
}
for (int i = 0; i < n; i++)
cin >> k[i];
if (okk) {
fill(loc, loc + VL, -1);
for (int i = 0; i < n; i++) {
f[i] = 1;
for (int j = 0; j < VL; j++){
if (loc[j] < 0) continue;
if (f[loc[j]] + 1 > f[i] && ok(loc[j], i)){
f[i] = f[loc[j]] + 1;
pr[i] = loc[j];
}
}
if (f[i] > ans){
ans = f[i];
nm = i;
}
if (f[i] > ff[a[i]]){
ff[a[i]]= f[i];
loc[a[i]] = i;
}
}
} else {
for (int i = 0; i < n; i++) {
f[i] = 1;
for (int j = i - 1; j >= 0; j--)
if (f[j] + 1 > f[i] && ok(j, i)){
f[i] = f[j] + 1;
pr[i] = j;
}
if (f[i] > ans){
ans = f[i];
nm = i;
}
}
}
for (;;){
vc.PB(nm + 1);
if (f[nm] == 1) break;
nm = pr[nm];
}
reverse(all(vc));
cout << sz(vc) << '\n';
for (int x : vc)
cout << x << " ";
return 0;
}
# | 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... |