Submission #1127952

#TimeUsernameProblemLanguageResultExecution timeMemory
1127952FucKanhLongest beautiful sequence (IZhO17_subsequence)C++17
40 / 100
6093 ms96052 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> using namespace std; const int half = 10; const int maxn = 1e5 + 2; int n; int a[maxn], k[maxn]; int l[maxn], r[maxn]; int trace[maxn],arr[maxn]; int bc[1<<half][1<<half]; pii dp[1<<half][1<<half][half + 1]; void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> k[i]; memset(dp,-1,sizeof(dp)); for (int i = 0; i < (1<<half); i++) { for (int j = 0; j < (1<<half); j++) { bc[i][j] = __builtin_popcount(i & j); } } int ans = 0, pos = 0; for (int i = 1; i <= n; i++) { int len = 1; int r = a[i] & ((1<<half)-1); int l = a[i] >> half; for (int state = 0; state < (1<<half); ++state) { if (bc[l][state] > k[i] || k[i] - bc[l][state] > 10) continue; pii &tmp = dp[state][r][k[i] - bc[l][state]]; if (len < tmp.first + 1) { len = tmp.first + 1; trace[i] = tmp.second; } } if (ans < len) { ans = len; pos = i; } for (int state = 0; state < (1<<half); ++state) { pii &tmp = dp[l][state][bc[state][r]]; if (tmp.first < len) { tmp.first = len; tmp.second = i; } } } cout << ans << '\n'; int cnt = 0; while (trace[pos]) { arr[++cnt] = pos; pos = trace[pos]; } arr[++cnt] = pos; for (int i = cnt ; i >= 1; i--) { cout << arr[i] << " "; } } signed main() { cin.tie(0) -> sync_with_stdio(0); solve(); 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...