Submission #765707

#TimeUsernameProblemLanguageResultExecution timeMemory
765707vjudge1Longest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
44 ms484 KiB
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 5005;
int a[maxn], k[maxn];
int dp[maxn], pre[maxn];
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> k[i];
    }
    a[0] = 1048575;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            if (j == 0 || __builtin_popcount(a[i] & a[j]) == k[i]) {
                if (dp[i] < dp[j] + 1) {
                    dp[i] = dp[j] + 1;
                    pre[i] = j;
                }
            }
        }
    }
    int mx = 0, pos = 0;
    for (int i = 1; i <= n; i++) {
        if (dp[i] > mx) {
            mx = dp[i];
            pos = i;
        }
    }
    cout << mx << endl;
    stack<int> s;
    while (pos) {
        s.push(pos);
        pos = pre[pos];
    }
    while (!s.empty()) {
        cout << s.top() << " ";
        s.pop();
    }
    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...