제출 #1264852

#제출 시각아이디문제언어결과실행 시간메모리
1264852yoshi_33550336Longest beautiful sequence (IZhO17_subsequence)C++20
100 / 100
1339 ms88492 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
#include <bits/stdc++.h>
using namespace std;
#ifndef yoshi_likes_e4
#define endl '\n'
#endif
#define problem ""
#define multitest 0
#define debug(x) cerr << #x << " = " << x << endl;
void init()
{
}
int jca[12][512][2048];
int jcat[12][512][2048];
void Yoshi()
{
    memset(jca,sizeof(jca),0xff);
    memset(jcat,sizeof(jcat),0xff);
    int n;
    cin >> n;
    vector<int> a(n), k(n);
    for (auto &i : a)
        cin >> i;
    for (auto &i : k)
        cin >> i;
    vector<int> dp(n, 1);
    vector<int> trace(n, -1);
    for (int i = 0; i < n; i++)
    {
        for (int low = 0; low < 512; low++)
        {
            const int bp = __builtin_popcountll(a[i] & low);
            if (bp > k[i] || k[i] - bp >= 12 || jca[k[i] - bp][low][a[i] >> 9] < dp[i])
                continue;
            else
            {
                dp[i] = 1 + jca[k[i] - bp][low][a[i] >> 9];
                trace[i] = jcat[k[i] - bp][low][a[i] >> 9];
            }
        }
        int lowBit = a[i] & 511;
        for (int highA = 0; highA < 2048; highA++)
        {
            const int bp = __builtin_popcountll(highA & (a[i] >> 9));
            if (jca[bp][lowBit][highA] < dp[i])
            {
                jcat[bp][lowBit][highA] = i;
                jca[bp][lowBit][highA] = dp[i];
            }
        }
    }
    int pos = max_element(dp.begin(), dp.end()) - dp.begin();
    cout << dp[pos] << endl;
    deque<int> dq;
    while (pos != -1)
    {
        dq.push_front(pos + 1);
        pos = trace[pos];
    }
    for (auto &i : dq)
        cout << i << " ";
    cout << endl;
}
signed main()
{
#ifndef yoshi_likes_e4
    ios::sync_with_stdio(0);
    cin.tie(0);
    if (fopen(problem ".inp", "r"))
    {
        freopen(problem ".inp", "r", stdin);
        freopen(problem ".out", "w", stdout);
    }
#endif
    init();
    int t = 1;
#if multitest
    cin >> t;
#endif
    while (t--)
        Yoshi();
}

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(problem ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(problem ".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...