제출 #522353

#제출 시각아이디문제언어결과실행 시간메모리
522353dostigatorLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6069 ms4472 KiB
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mii map<int,int>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define pb push_back
#define vt vector
//#define endl '\n'
#define X first
#define Y second
typedef long double ld;
typedef long long ll;
const int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=6e5;
const ll mod=1e9+7,inf=1e18;
int dp[N],pr[N];
void solve(){
    int n;
    cin>>n;
    int a[n+2],k[n+2];
    fill(dp,dp+N,1);
    dp[0]=0;
    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) for(int j=0; j<i; ++j){
        int x=a[j]&a[i];
        if(popcnt(x)==k[i] || j==0){
            dp[i]=max(dp[i],dp[j]+1);
            if(dp[i]==dp[j]+1) pr[i]=j;
        }
    }
    int mx=0,pos=0;
    for(int i=1; i<=n; ++i){
        mx=max(mx,dp[i]);
        if(mx==dp[i]) pos=i;
    }
    cout<<mx<<endl;
    vt<int>v;
    while(pos!=0){
        v.pb(pos);
        pos=pr[pos];
    }
    sort(all(v));
    for(int x:v)cout<<x<<' ';
}
int main() {
    IShowSpeed;
    int tt=1;
    //cin>>tt;
    while(tt--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...