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 maxn 100010
using namespace std;
int n, a[maxn], k[maxn], ans;
pair<int, int> dp[maxn];
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i = 0; i < n; ++i){
cin >> k[i];
}
if(n <= 5000){
for(int i = 0; i < n; ++i){
dp[i] = {1, -1};
for(int j = 0; j < i; ++j){
if(__builtin_popcount(a[i]&a[j]) == k[i]){
if(dp[j].first+1 > dp[i].first){
dp[i] = dp[j];
dp[i].second = j;
dp[i].first = dp[j].first+1;
}
}
}
}
pair<int, int> ans = {1, -1};
int idx = 0;
for(int i = 0; i < n; ++i){
ans = max(ans, dp[i]);
if(ans == dp[i]){
idx = i;
}
}
vector<int> res;
while(true){
res.push_back(idx+1);
if(ans.second == -1){
break;
}
idx = ans.second;
ans = dp[ans.second];
}
reverse(res.begin(), res.end());
cout << res.size() << '\n';
for(auto tmp:res){
cout << tmp<<'\n';
}
}
}
# | 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... |