Submission #38243

#TimeUsernameProblemLanguageResultExecution timeMemory
38243antimirageLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
83 ms2092 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 5005;

int n, a[N], b[N], dp[N], ans, p[N], res;

vector <int> path;

main ()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);

    for (int i = 1; i <= n; i++)
        scanf("%d", &b[i]), dp[i] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = i - 1; j >= 1; j--)
        {
            if ( __builtin_popcount(a[i] & a[j]) == b[i] )
            {
                if (dp[i] < dp[j] + 1)
                {
                    p[i] = j;
                    dp[i] = max( dp[i], dp[j] + 1 );
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (dp[i] > ans)
        {
            ans = dp[i];
            res = i;
        }
    }
    cout << ans << endl;

    while (res)
    {
        path.pb( res );
        res = p[res];
    }
    reverse(all(path));
    for (auto x : path)
        printf("%d ", x);
}
/**
4
1 2 3 4
10 0 1 0
**/

Compilation message (stderr)

subsequence.cpp:31:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:35:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
subsequence.cpp:38:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b[i]), dp[i] = 1;
                                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...