Submission #94418

#TimeUsernameProblemLanguageResultExecution timeMemory
94418KastandaLongest beautiful sequence (IZhO17_subsequence)C++11
23 / 100
6087 ms1884 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
using namespace std;
const int N = 100005;
int n, ts, A[N], K[N], dp[N], P[N], R[N];
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;
    for (int i = 1; i <= n; i++)
    {
        int k = K[i];
        int Mx = 0, a = A[i], p = 0;
        for (int j = 1; j < i; j++)
            if (__builtin_popcount(a & A[j]) == k && Mx < dp[j])
                {Mx = dp[j]; p = j;}
        dp[i] = Mx + 1; P[i] = p;
        if (dp[i] > dp[nw])
            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)

subsequence.cpp:4:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
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:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &K[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...