Submission #133860

#TimeUsernameProblemLanguageResultExecution timeMemory
133860KastandaLongest beautiful sequence (IZhO17_subsequence)C++11
40 / 100
6013 ms54024 KiB
// ItnoE
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, SQ = 1024;
int n, A[N], P[N];
pair < int , int > dp[21][SQ][SQ];
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]);
    int Mx = 0, Bi = 0;
    for (int i = 1; i <= n; i ++)
    {
        int k, a = A[i];
        scanf("%d", &k);
        pair < int , int > Bst = {0, 0};
        for (int j = 0; j < SQ; j ++)
            if (k >= __builtin_popcount(a >> 10 & j))
                Max(Bst, dp[k - __builtin_popcount(a >> 10 & j)][a & 1023][j]);
        P[i] = Bst.second; Bst.first ++; Bst.second = i;
        for (int j = 0; j < SQ; j ++)
            Max(dp[__builtin_popcount(a & j)][j][a >> 10], Bst);
        if (Bst.first > Mx)
            Mx = Bst.first, Bi = i;
    }
    vector < int > R;
    while (Bi)
        R.push_back(Bi), Bi = P[Bi];
    reverse(R.begin(), R.end());
    printf("%d\n", (int)R.size());
    for (int v : R)
        printf("%d ", v);
    return 0;
}

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
subsequence.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
         ~~~~~^~~~~~~~~~~~~
subsequence.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &k);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...