제출 #1108845

#제출 시각아이디문제언어결과실행 시간메모리
1108845dubabubaLongest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
121 ms2888 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 10; int a[mxn], dp[mxn]; int b[mxn], pr[mxn]; int n; const int LOG = 8; int mx[1 << LOG]; void solve() { int id = 1; for(int i = 1; i <= n; i++) { dp[i] = 1; for(int bit = 0; bit < (1 << LOG); bit++) { int t = a[i] & bit; if(__builtin_popcount(t) != b[i]) continue; int j = mx[bit]; if(dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; pr[i] = j; } } if(dp[id] < dp[i]) id = i; if(dp[mx[a[i]]] < dp[i]) mx[a[i]] = i; } vector<int> ind; while(id) { ind.push_back(id); id = pr[id]; } reverse(ind.begin(), ind.end()); cout << ind.size() << endl; for(int i : ind) cout << i << ' '; cout << endl; exit(0); } int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; if(n > 5000) solve(); int id = 1; for(int i = 1; i <= n; i++) { dp[i] = 1; for(int j = 1; j < i; j++) { int t = a[i] & a[j]; if(__builtin_popcount(t) != b[i]) continue; if(dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; pr[i] = j; } } if(dp[id] < dp[i]) id = i; } vector<int> ind; while(id) { ind.push_back(id); id = pr[id]; } reverse(ind.begin(), ind.end()); // if(ind.size()) return 1; cout << (int)ind.size() << endl; for(int i : ind) cout << i << ' '; cout << endl; 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...