제출 #1098795

#제출 시각아이디문제언어결과실행 시간메모리
1098795vjudge1Longest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
4143 ms29936 KiB
#include<bits/stdc++.h> using namespace std; using lli = long long; const int maxN = 2e6 + 5; const int maxD = (1 << 10) + 5; int f[maxN],n,a[maxN],k[maxN],tr[maxN]; int dp[11][maxD][maxD]; vector<int> q; void input() { cin >> n; for (int i = 1;i <= n;++i) cin >> a[i]; for (int i = 1;i <= n;++i) cin >> k[i]; } void solve() { f[0] = 0; int res = 1; for (int i = 1;i <= n;++i) { f[i] = 1; int pre = a[i] / (1 << 10); int suf = a[i] % (1 << 10); for (int k0 = 0;k0 < 11;++k0) for (int j = 0;j < (1 << 10);++j) if (k0 + __builtin_popcountll(suf & j) == k[i] && f[dp[k0][pre][j]] + 1 > f[i]) { f[i] = f[dp[k0][pre][j]] + 1; tr[i] = dp[k0][pre][j]; } for (int j = 0;j < (1 << 10);++j) if (f[dp[__builtin_popcountll(j & pre)][j][suf]] < f[i]) dp[__builtin_popcountll(j & pre)][j][suf] = i; if (f[res] < f[i]) res = i; } cout << f[res] << "\n"; do { q.push_back(res); res = tr[res]; } while (res != 0); reverse(q.begin(),q.end()); for (int v : q) cout << v << " "; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("A.inp","r",stdin); // freopen("A.out","w",stdout); input(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...