# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1025250 | hasan2006 | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 1696 ms | 80448 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>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 1e5 + 9 , mod = 1e9 + 7;
int a[N] , b[N] , dp[11][1 << 10][1 << 10][2] , c[N] , d[N] ;
void solve()
{
ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ;
cin>>n;
for(i = 1; i <= n; i++)
cin>>a[i];
for(i = 1; i <= n; i++)
cin>>b[i];
pair<int,int>p;
for(i = 0; i < (1 << 10); i++)
c[i] = __builtin_popcount(i);
pair<int,int>ans = {-1, -1};
for(i = 1; i <= n; i++){
l = r= 0;
x = 1 , y = 0;
for(j = 0; j < 10; j++){
if((1 << j) & a[i])
l += (1 << j);
if((1 << (j + 10)) & a[i])
r += (1 << j);
}
for(j = 0; j < (1 << 10); j++){
f = b[i] - c[l & j];
if(f < 0 || f > 10)
continue;
if(x < dp[f][j][r][0] + 1)
x = dp[f][j][r][0] + 1 , y = dp[f][j][r][1];
}
d[i] = y;
for(j = 0; j < (1 << 10); j++){
f = c[r & j];
if(dp[f][l][j][0] < x)
dp[f][l][j][0] = x , dp[f][l][j][1] = i;
}
if(ans.fi < x)
ans = {x , i};
}
vector<int>vc;
while(ans.se){
vc.pb(ans.se);
ans.se = d[ans.se];
}
cout<<vc.size()<<"\n";
reverse(all(vc));
for(auto to : vc)
cout<<to<<" ";
}
int main(){
TL;
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
}
// Author : حسن
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... |