제출 #172860

#제출 시각아이디문제언어결과실행 시간메모리
172860VEGAnnLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
7 ms376 KiB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 510;
const int N2 = N * N;
const int PW = 20;
const int oo = 2e9;
vector<int> vc;
int n, a[N], k[N], f[N], ans, nm;

bool ok(int x, int y, int vl){
    return (__builtin_popcount(a[x] & a[y]) == k[vl]);
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("in.txt","r",stdin);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> k[i];

    for (int i = 0; i < n; i++){
        f[i] = 1;
        for (int j = i - 1; j >= 0; j--)
            if (ok(j, i, f[j]))
                f[i] = max(f[i], f[j] + 1);
        if (ans < f[i]){
            ans = f[i];
            nm = i;
        }
    }
    cout << ans << '\n';

    vc.clear();
    for (int i = nm; ;){
        vc.PB(i);
        if (f[i] == 1) break;
        for (int j = i - 1; ; j--)
            if (f[j] + 1 == f[i] && ok(j, i, f[j])){
                i = j;
                break;
            }
    }
    reverse(all(vc));
    for (int x : vc)
        cout << x + 1 << " ";
    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...