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 int
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,a[5001],k[5001],dp[1001][1001],ans,ind,p;
vector<ll>v;
int main(){
std::ios::sync_with_stdio(false);
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=1; i<=n; i++)dp[i][1] = i;
ans = 1;
ind = 1;
for(int i=1; i<=n; i++){
p = -1;
for(int j = i-1; j>=1; j--){
if(__builtin_popcount((a[j]&a[i])) == k[i]){
p = j;
break;
}
}
for(int j=2; j<=n; j++){
if(dp[p][j-1])dp[i][j] = p;
if(dp[i][j] && j > ans){
ans = j;
ind = i;
}
}
}
cout << ans << endl;
while(dp[ind][ans] != ind){
v.pb(ind);
ind = dp[ind][ans];
ans--;
}
v.pb(ind);
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... |