This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()
const int N = (int)1e5+7;
int dp[N], p[N];
int c[1024][1024][11];
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie();
int n;
cin >> n;
int a[n+1], k[n+1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
cin >> k[i];
}
for(int i = 1; i <= n; i++){
int j = 0;
int top10 = (a[i] >> 10);
int last10 = (a[i] & 1023);
for(int mask = 0; mask < (1 << 10); mask++){
int cnt = k[i] - (__builtin_popcount(mask & last10));
if(cnt >= 0 and cnt <= 10){
if(dp[j] < dp[c[top10][mask][cnt]]){
j = c[top10][mask][cnt];
}
}
}
dp[i] = dp[j] + 1;
p[i] = j;
int cnt = 0;
for(int mask = 0; mask < (1 << 10); mask++){
cnt = __builtin_popcount(mask & top10);
if(dp[c[mask][last10][cnt]] < dp[i]){
c[mask][last10][cnt] = i;
}
}
}
int I = 0, ans = 0;
vector<int> path;
for(int i = 1; i <= n; i++){
if(dp[i] > ans){
I = i;
ans = dp[i];
}
}
while(I){
path.pb(I);
I = p[I];
}
reverse(all(path));
cout << ans << endl;
for(auto x : path){
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... |