Submission #1345978

#TimeUsernameProblemLanguageResultExecution timeMemory
1345978iamhereforfunLongest beautiful sequence (IZhO17_subsequence)C++20
0 / 100
1 ms580 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e5 + 5;
const int M = 1 << 10;
const int K = 19;
const int LG = 11;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

int n, a[N], b[N], ptr[N], num[N], cur;
pair<int, int> mn[M][M][LG];
vector<int> v;

inline void solve()
{
    cin >> n;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
    }
    for (int x = 1; x <= n; x++)
    {
        cin >> b[x];
    }
    for (int x = 1; x <= n; x++)
    {
        // for (int y = x + 1; y <= n; y++)
        // {
        //     cout << __builtin_popcount(a[x] & a[y]) << " ";
        // }
        // cout << "\n";
    }
    for (int x = 1; x <= n; x++)
    {
        int l = a[x] % M, r = a[x] / M;
        pair<int, int> ans = {0, 0};
        for (int y = 0; y < M; y++)
        {
            int i = __builtin_popcount(y & r);
            i = b[x] - i;
            if (i < 0 || i >= LG)
                continue;
            // if (mn[y][l][i].first != 0)
            // {
            //     cout << y << " " << l << " " << i << "\n";
            // }
            ans = max(ans, mn[y][l][i]);
        }
        ans.first++;
        ptr[x] = ans.second;
        num[x] = ans.first;
        // cout << ans.first << " " << ans.second << "\n";
        ans.second = x;
        for (int y = 0; y < M; y++)
        {
            int i = __builtin_popcount(y & l);
            if (i < 0 || i > LG)
                continue;
            mn[r][y][i] = max(mn[r][y][i], ans);
        }
    }
    cur = 1;
    for (int x = 2; x <= n; x++)
    {
        if (num[x] > num[cur])
            cur = x;
    }
    while (cur != 0)
    {
        v.push_back(cur);
        cur = ptr[cur];
    }
    reverse(v.begin(), v.end());
    cout << v.size() << "\n";
    // for (int i : v)
    //     cout << i << " ";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    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...