제출 #38247

#제출 시각아이디문제언어결과실행 시간메모리
38247antimirageLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
0 ms3580 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 = 1e5 + 5;

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

pair <int, int> mx[500];

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, mx[ a[i] ] = max( mx[ a[i] ], mk( 1, i ) );

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 256; j++)
        {
            if ( __builtin_popcount(a[i] & j) == b[i] )
            {
                if (dp[i] < dp[ mx[j].sc ] + 1)
                {
                    p[i] = mx[j].sc;
                    dp[i] = dp[ mx[j].sc ] + 1;
                }
            }
        }
        mx[ a[i] ] = max( mx[ a[i] ], mk( dp[i], i ) );
    }
    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
**/

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp:33:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:37:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
subsequence.cpp:40:82: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b[i]), dp[i] = 1, mx[ a[i] ] = max( mx[ a[i] ], mk( 1, 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...