Submission #198832

#TimeUsernameProblemLanguageResultExecution timeMemory
198832MetBLongest beautiful sequence (IZhO17_subsequence)C++14
0 / 100
38 ms46200 KiB
#include <bits/stdc++.h> #define N 1000001 using namespace std; typedef long long ll; const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3; int d[1 << 10][1 << 10][10], p[1 << 10][1 << 10][10], pc[1 << 20]; int a[N], k[N], n, bm = (1 << 10) - 1, ans, par[N], ind; int main () { cin >> n; for (int i = 0; i < (1 << 20); i++) pc[i] = __builtin_popcount (i); memset (p, -1, sizeof (p)); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> k[i]; } for (int i = 0; i < n; i++) { int x = 0; par[i] = -1; for (int j = 0; j < (1 << 10); j++) { int l = k[i] - pc[(j << 10) & a[i]]; if (x < d[j][a[i] & bm][l]) { par[i] = p[j][a[i] & bm][l]; x = d[j][a[i] & bm][l]; } } x++; for (int j = 0; j < (1 << 10); j++) { int& c = d[a[i] >> 10][j][pc[j & a[i]]]; if (x > c) { c = x; p[a[i] >> 10][j][pc[j & a[i]]] = i; } } if (x > ans) { ans = x; ind = i; } } vector <int> v; cout << ans << endl; while (ind != -1) { v.push_back (ind + 1); ind = par[ind]; } reverse (v.begin(), v.end()); for (int i : v) cout << i << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...