제출 #312277

#제출 시각아이디문제언어결과실행 시간메모리
312277ttnhuy313Longest beautiful sequence (IZhO17_subsequence)C++14
7 / 100
303 ms86680 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, half = (1 << 10) + 5, K = 21; int n, a[N], k[N], f[half][half][K], dp[N], trace[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("IZhO17_subsequence.INP", "r", stdin); // freopen("IZhO17_subsequence.OUT", "w", stdout); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) cin >> k[i]; int halve = (1 << 10) - 1, res = 0; for (int i = 1; i <= n; ++i) { int s = (a[i] & halve); dp[i] = 1; for (int fd = 0; fd < halve; ++fd) { int fbc = __builtin_popcount((a[i] >> 10) & fd); if (fbc > k[i]) continue; int val = dp[f[fd][s][k[i] - fbc]] + 1; if (dp[i] < val) { dp[i] = val; trace[i] = f[fd][s][k[i] - fbc]; } } for (int sc = 0; sc < halve; ++sc) { int pre = dp[f[a[i] >> 10][sc][__builtin_popcount(s & sc)]]; if (pre < dp[i]) { f[a[i] >> 10][sc][__builtin_popcount(s & sc)] = i; } } res = max(res, dp[i]); } cout << res << endl; int i; for (i = 1; i <= n; ++i) if (dp[i] == res) break; vector <int> ans; ans.clear(); while (i) { ans.push_back(i); i = trace[i]; } reverse(ans.begin(), ans.end()); for (int j : ans) cout << j << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...