| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 94439 | Kastanda | Longest beautiful sequence (IZhO17_subsequence) | C++11 | 242 ms | 98372 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, SQ = 1024;
int n, ts, A[N], K[N], P[N], R[N];
pair < int , int > dp[SQ+1][SQ+1][11+1];
inline void MAX(pair < int , int > &a, pair < int , int > b)
{
    a = max(a, b);
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]);
    for (int i = 1; i <= n; i++)
        scanf("%d", &K[i]);
    int nw = 0, _max = 0;
    for (int i = 1; i <= n; i++)
    {
        int a = A[i], k = K[i];
        pair < int , int > Mx = {0, 0};
        if (__builtin_popcount(a) >= k)
            for (int j = 0; j < SQ; j++)
                if (k - __builtin_popcount((a >> 10) & j) >= 0)
                    MAX(Mx, dp[j][a & (SQ - 1)][k - __builtin_popcount((a >> 10) & j)]);
        Mx.first ++;
        P[i] = Mx.second;
        Mx.second = i;
        for (int j = 0; j < SQ; j++)
            MAX(dp[a >> 10][j][__builtin_popcount(a & (SQ - 1) & j)], Mx);
        if (Mx.first > _max)
            _max = Mx.first, nw = i;
    }
    while (nw)
    {
        R[ts ++] = nw;
        nw = P[nw];
    }
    printf("%d\n", ts);
    for (int i = ts - 1; ~i; i--)
        printf("%d ", R[i]);
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
