제출 #314209

#제출 시각아이디문제언어결과실행 시간메모리
314209TricksterLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
3565 ms167232 KiB
#include <bits/stdc++.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define N 100010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}

int n;
int v[N], k[N], Pr[N];
int dp[1<<10][1<<10][20];
int in[1<<10][1<<10][20];

int main()
{
    cin >> n;

    for(int i = 1; i <= n; i++) cin >> v[i];
    for(int i = 1; i <= n; i++) cin >> k[i];

    int mx = 0, pos = 0;
    for(int i = 1; i <= n; i++) {
        int now = 1, l = 0, r = 0;

        for(int h = 0; h < 10; h++) if((1<<h)&v[i]) l += (1<<h);
        for(int h = 10; h < 20; h++) if((1<<h)&v[i]) r += (1<<h);

        r >>= 10;

        for(int h = 0; h < (1<<10); h++) {
            int y = k[i] - __builtin_popcount(h&l);

            if(y >= 0 && y <= 10 && dp[h][r][y] >= now) {
                now = dp[h][r][y] + 1;
                Pr[i] = in[h][r][y];
            }
        }

        for(int h = 0; h < (1<<10); h++) {
            int y = __builtin_popcount(h&r);

            if(dp[l][h][y] < now) {
                dp[l][h][y] = now;
                in[l][h][y] = i;
            }
        }

        if(mx < now) mx = now, pos = i;
    }

    vector <int> A;
    while(pos) A.pb(pos), pos = Pr[pos];
    reverse(A.begin(), A.end());

    cout << A.size() << "\n";
    for(auto i: A) cout << i << " ";
}
/*
4
1 2 3 4
10 0 1 0
5
5 3 5 3 5
10 1 20 1 20
*/

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

subsequence.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   23 | #pragma GCC optimization ("O3")
      | 
subsequence.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   24 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...