제출 #1299661

#제출 시각아이디문제언어결과실행 시간메모리
1299661daotuankhoiLongest beautiful sequence (IZhO17_subsequence)C++20
100 / 100
2519 ms128840 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

const int MAXN = 2e5 + 5;
pair<int, int> dp[1 << 10][1 << 10][15];
int b[1 << 10][1 << 10];
int prv[MAXN], a[MAXN], k[MAXN];
int main() {
    #define NAME "test"
    if (fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> k[i];
    }
    memset(dp, -0x3f, sizeof dp);

    for (int i = 0; i < (1 << 10); i++) for (int j = 0; j < (1 << 10); j++) {
        b[i][j] = __builtin_popcount(i & j);
    }
    int ans = 0, pos = 0;
    for (int i = 1; i <= n; i++) {
        int mx = 1;
        int l = a[i] >> 10;
        int r = a[i] & ((1 << 10) - 1);
        for (int j = 0; j < (1 << 10); j++) {
            int need = k[i] - b[j][l];
            if (need < 0 || need > 10) continue;
            if (ckmax(mx, dp[j][r][need].fi + 1)) {
                prv[i] = dp[j][r][need].se;
            }
        }
        if (ckmax(ans, mx)) {
            pos = i;
        }
        for (int j = 0; j < (1 << 10); j++) {
            if (ckmax(dp[l][j][b[j][r]].fi, mx)) {
                dp[l][j][b[j][r]].se = i;
            }
        }
    }
    cout << ans << '\n';
    vector<int> v;
    while (ans--) {
        v.emplace_back(pos);
        pos = prv[pos];
    }
    while (v.size()) {
        cout << v.back() << ' ';
        v.pop_back();
    }
    return 0;
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...