# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502599 | Aktan | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1 ms | 420 KiB |
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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17,N=1e5;
int a[5005],b[5005];
vector<int> dp[5005];
main(){
int n;
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
}
for(int i=1;i<=n;i++){
cin >> b[i];
}
int ans=-1;
dp[1].push_back(1);
int m=0,e=-1;
for(int i=1;i<=n;i++){
bool h=0;
for(int j=i-1;j>=1;j--){
if(__builtin_popcount(a[i]&a[j])==b[i] && dp[j].size()>dp[i].size()){
h=1;
dp[i]=dp[j];
dp[i].push_back(i);
}
}
if(dp[i].empty()){
dp[i].push_back(i);
}
if(dp[i].size()>m){
m=dp[i].size();
e=i;
}
}
cout << dp[e].size() << endl;
for(auto x : dp[e]){
cout << x << " ";
}
}
Compilation message (stderr)
# | 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... |