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 ll long long
#define fi first
#define se second
#define endl '\n'
#define mask(i) (1LL << (i))
#define task "name"
#define ull unsigned long long
using namespace std;
const ll mxN = 220797 + 7;
const ll inf = 1e9 + 277;
const ll mod = 2147483648;
const ll infll = 1e18 + 7;
const ll base = 307;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int a[mxN];
int k[mxN];
int pre[mxN];
int cntbit[(1 << 10) + 7];
pair<int , int> dp[(1 << 10) + 7][(1 << 10) + 7][12];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("task.inp" , "r" , stdin);
//freopen("task.out" , "w" , stdout);
int n;
cin >> n;
for(int i = 1 ; i <= n ; i++) cin >> a[i];
for(int i = 1 ; i <= n ; i++) cin >> k[i];
for(int mask = 0 ; mask < (1 << 10) ; mask++) cntbit[mask] = __builtin_popcount(mask);
pair<int , int> ans = {0 , 0};
for(int i = 1 ; i <= n ; i++) {
pair<int , int> tmp = {0 , 0};
int left = (a[i] & ((1 << 10) - 1));
for(int mask = 0 ; mask < (1 << 10) ; mask++) {
int need = k[i] - cntbit[(a[i] >> 10) & mask];
if(need >= 0 && need <= 10) maximize(tmp , dp[left][mask][need]);
}
pre[i] = tmp.se;
tmp.fi++;
tmp.se = i;
maximize(ans , tmp);
for(int mask = 0 ; mask < (1 << 10) ; mask++) {
maximize(dp[mask][a[i] >> 10][cntbit[mask & a[i]]] , tmp);
}
}
cout << ans.fi << endl;
vector<int> res;
int x = ans.se;
while(x != 0) {
res.push_back(x);
x = pre[x];
}
reverse(res.begin() , res.end());
for(int i : res) cout << i << ' ';
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... |