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 pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
const int NM = 1e5;
int n, a[NM+5], k[NM+5], dp[NM+5], trace[NM+5], best = 1;
int mx[1024][1024][11];
vector <int> v;
void chkmax(pii &a, pii b){
if (b.fi > a.fi) a = b;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> k[i];
for (int i = 0; i < 1024; i++)
for (int j = 0; j < 1024; j++)
for (int t = 0; t <= 10; t++)
mx[i][j][t] = -1;
for (int i = 1; i <= n; i++){
dp[i] = 1;
for (int j = 0; j < 1024; j++){
int tmp = __builtin_popcount(a[i]&j);
if (tmp > k[i]) continue;
int t = mx[j][a[i]>>10][k[i]-tmp];
if (t != -1 && dp[t]+1 > dp[i]){
dp[i] = dp[t]+1;
trace[i] = t;
}
}
for (int j = 0; j < 1024; j++){
int &t = mx[a[i]&1023][j][__builtin_popcount((a[i]>>10)&j)];
if (t == -1 || dp[i] > dp[t]) t = i;
}
if (dp[i] > dp[best]){
best = i;
}
}
cout << dp[best] << '\n';
while (best > 0){
v.push_back(best);
best = trace[best];
}
for (int i = (int)v.size()-1; i >= 0; i--) cout << v[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... |