Submission #541025

#TimeUsernameProblemLanguageResultExecution timeMemory
541025i_am_noobLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
319 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")

#define ll long long
//#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define inf 1010000000
//#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif

const int mod=1000000007;
const int maxn=100005,maxm=18,maxk=7777714;

//i_am_noob
const int magic=10;
int n,a[maxn],b[maxn],maxx[maxn],pre[maxn];
pii dp[pow2(magic)][pow2(magic)][magic+1];
vector<int> res;

void orzck(){
    cin >> n;
    rep(n) cin >> a[i];
    rep(n) cin >> b[i];
    rep(pow2(magic)) rep1(j,pow2(magic)) rep1(k,magic+1) dp[i][j][k]={0,-1};
    rep(n){
        rep1(mask,pow2(magic)){
            int cnt=b[i]-__builtin_popcountll((a[i]>>magic)&mask);
            if(cnt<0||cnt>magic) continue;
            pii p=dp[mask][a[i]&(pow2(magic)-1)][cnt];
            if(p.first+1>maxx[i]){
                maxx[i]=p.first+1;
                pre[i]=p.second;
            }
        }
        rep1(mask,pow2(magic)){
            pii& p=dp[a[i]>>magic][mask][__builtin_popcountll(mask&a[i]&(pow2(magic)-1))];
            if(maxx[i]>p.first){
                p.first=maxx[i];
                p.second=i;
            }
        }
    }
    int cur=max_element(maxx,maxx+n)-maxx;
    while(cur>=0){
        res.pb(cur);
        cur=pre[cur];
    }
    reverse(all(res));
    cout << sz(res) << "\n";
    for(auto i: res) cout << i+1 << ' ';
    cout << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    orzck();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...