This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
const int N = (int)1e5 + 7; // make sure this is right
const int M = (int)9e7 + 7;
const int inf = (int)2e9 + 7;
const ll INF = (ll)3e18 + 7;
const ll MOD = (ll)1e9 + 7; // make sure this is right
bool bit(int x, int i) {
return x >> i & 1;
}
int sum(int x, int y) {
x += y;
if(x >= MOD) x -= MOD;
return x;
}
int n, a[N], b[N], pr[N], d[N];
pair<int, int> dp[300];
void solve() {
cin >> n;
bool ok = 1;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
ok &= (a[i] < 256);
}
for(int i = 1; i <= n; ++i) cin >> b[i];
int s = 0, mx = 0;
if(ok) {
for(int i = 1; i <= n; ++i) {
pair<int, int> p = {1, i};
bool e = 0;
if(dp[a[i]].x == 0) {
dp[a[i]] = p;
e = 1;
}
for(int x = 0; x < 256; ++x) {
if(e && x == a[i]) continue;
if(__builtin_popcount(x & a[i]) == b[i]) {
if(dp[x].x + 1 > dp[a[i]].x) {
dp[a[i]].x = dp[x].x + 1;
pr[i] = dp[x].y;
}
}
}
dp[a[i]].y = i;
if(dp[a[i]].x > mx) {
mx = dp[a[i]].x;
s = i;
}
}
} else {
for(int i = 1; i <= n; ++i) {
d[i] = 1;
for(int j = i - 1; j >= 1; --j) {
int x = __builtin_popcount(a[j] & a[i]);
if(x == b[i]) {
if(d[j] + 1 > d[i]) {
d[i] = d[j] + 1;
pr[i] = j;
}
}
}
if(d[i] > d[s]) s = i;
}
}
vector<int> ans;
while(s) {
ans.pb(s);
s = pr[s];
}
reverse(all(ans));
cout << sz(ans) << "\n";
for(auto x : ans) cout << x << ' ';
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case #" << i << ": ";
solve();
}
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... |