제출 #907224

#제출 시각아이디문제언어결과실행 시간메모리
907224daoquanglinh2007Longest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
2962 ms48468 KiB
#include <bits/stdc++.h> using namespace std; const int NM = 1e5; int n, a[NM+5], k[NM+5], dp[NM+5], trace[NM+5], best = 1; int popcnt[1024], mx[1024][1024][11]; vector <int> v; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> k[i]; for (int i = 0; i < 1024; i++) popcnt[i] = __builtin_popcount(i); for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) for (int t = 0; t <= 10; t++) mx[i][j][t] = -1; for (int i = 1; i <= n; i++){ dp[i] = 1; for (int j = 0; j < 1024; j++){ int tmp = popcnt[a[i]&j]; if (k[i]-tmp < 0 || k[i]-tmp > 10) continue; int t = mx[j][a[i]>>10][k[i]-tmp]; if (t != -1 && dp[t]+1 > dp[i]){ dp[i] = dp[t]+1; trace[i] = t; } } for (int j = 0; j < 1024; j++){ int &t = mx[a[i]&1023][j][popcnt[(a[i]>>10)&j]]; if (t == -1 || dp[i] > dp[t]) t = i; } if (dp[i] > dp[best]){ best = i; } } cout << dp[best] << '\n'; while (best > 0){ v.push_back(best); best = trace[best]; } for (int i = (int)v.size()-1; i >= 0; i--) cout << v[i] << ' '; 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...