Submission #854094

#TimeUsernameProblemLanguageResultExecution timeMemory
854094The_SamuraiLongest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
3 ms348 KiB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    freopen("subsequence.in", "r", stdin);
    freopen("subsequence.out", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> a(n + 1), k(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> k[i];
    if (n <= 1e5 and *max_element(a.begin(), a.end()) <= (1 << 20)) {
        vector<int> dp(n + 1, 1), par(n + 1);
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                if (__builtin_popcount(a[i] & a[j]) == k[i] and dp[i] < dp[j] + 1) {
                    dp[i] = dp[j] + 1;
                    par[i] = j;
                }
            }
        }
        vector<int> way = {(int) (max_element(dp.begin() + 1, dp.end()) - dp.begin())};
        while (dp[way.back()] != 1) way.emplace_back(par[way.back()]);
        reverse(way.begin(), way.end());
        cout << way.size() << '\n';
        for (int x: way) cout << x << ' ';
        return 0;
    }
}

Compilation message (stderr)

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