Submission #969466

# Submission time Handle Problem Language Result Execution time Memory
969466 2024-04-25T08:14:42 Z noyancanturk Longest beautiful sequence (IZhO17_subsequence) C++17
0 / 100
1 ms 856 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int lim=1e6+100;
const int mod=1e9+7;
    
using pii=pair<int,int>;

const int lglim=10;

int dp[1<<lglim][1<<lglim][11];
int pcnt[1<<lglim];
const int coolmask=(1<<lglim)-1;

void solve(){
    for(int i=0;i<(1<<lglim);i++){
        pcnt[i]=__popcount(i);
    }
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    int totans=0;
    int ans[n];
    for(int i=0;i<n;i++){
        int first=a[i]&coolmask,second=(a[i]>>lglim)&coolmask;
        ans[i]=1;
        for(int j=0;j<(1<<lglim);j++){
            int need=b[i]-pcnt[first&j];
            if(0<=need&&need<=10){
                ans[i]=max(ans[i],dp[j][second][need]+1);
            }
        }
        for(int j=0;j<(1<<lglim);j++){
            dp[first][j][pcnt[second&j]]=max(
                dp[first][j][pcnt[second&j]],
                ans[i]
            );
        }
        if(ans[totans]<ans[i])totans=i;
    }
    cout<<"0\n";
    return;
    cout<<ans[totans]<<"\n";
    stack<int>toprint;
    toprint.push(totans);
    for(int i=totans-1;0<=i;i--){
        if(pcnt[a[i]&a[totans]]==b[totans]&&ans[i]==ans[totans]-1){
            toprint.push(i);
            totans=i;
        }
    }
    while(toprint.size()){
        cout<<toprint.top()+1<<" ";
        toprint.pop();
    }
}
    
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB incorrect length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB incorrect length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB incorrect length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB incorrect length
2 Halted 0 ms 0 KB -