제출 #1264718

#제출 시각아이디문제언어결과실행 시간메모리
1264718yoshi_33550336Longest beautiful sequence (IZhO17_subsequence)C++20
23 / 100
36 ms1864 KiB
#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()
{
}
void Yoshi()
{
    int n;
    cin >> n;
    vector<int> a(n), k(n);
    for (auto &i : a)
        cin >> i;
    for (auto &i : k)
        cin >> i;
    if (n <= 5000)
    {
        vector<int> dp(n, 1);
        vector<int> trace(n, -1);
        for (int i = 1; i < n; i++)
            for (int j = 0; j < i; j++)
                if (__builtin_popcountll(a[i] & a[j]) == k[i] && dp[j] + 1 > dp[i])
                    dp[i] = dp[j] + 1, trace[i] = j;
        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;
    }
    else
    {
        vector<int> jc(256, -1);
        vector<int> jct(256, -1);
        vector<vector<vector<int>>> jca(16, vector<vector<int>>(16, vector<int>(5, -1)));
        vector<vector<vector<int>>> jcat(16, vector<vector<int>>(16, vector<int>(5, -1)));
        vector<int> dp(n, 1);
        vector<int> trace(n, -1);
        for (int i = 0; i < n; i++)
        {
            for (int low = 0; low < 16; low++)
                if (__builtin_popcountll(a[i] & low) > k[i] || k[i] - __builtin_popcountll(a[i] & low) >= 5 ||
                    jca[low][a[i] >> 4][k[i] - __builtin_popcountll(a[i] & low)] < dp[i])
                    continue;
                else
                    dp[i] = 1 + jca[low][a[i] >> 4][k[i] - __builtin_popcountll(a[i] & low)],
                    trace[i] = jcat[low][a[i] >> 4][k[i] - __builtin_popcountll(a[i] & low)];
            int lowBit = a[i] & 15;
            for (int highA = 0; highA < 16; highA++)
                jca[lowBit][highA][__builtin_popcountll(highA & (a[i] >> 4))] =
                    max(jca[lowBit][highA][__builtin_popcountll(highA & (a[i] >> 4))], dp[i]);
            for (int highA = 0; highA < 16; highA++)
                if (jca[lowBit][highA][__builtin_popcountll(highA & (a[i] >> 4))] < dp[i])
                    jcat[lowBit][highA][__builtin_popcountll(highA & (a[i] >> 4))] = 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:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(problem ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         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...