제출 #1108841

#제출 시각아이디문제언어결과실행 시간메모리
1108841dubabubaLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
48 ms592 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 5050; int a[mxn], dp[mxn]; int b[mxn], pr[mxn]; int n; int main() { // #ifndef LOCAL // freopen("subsequence.in", "r", stdin); // freopen("subsequence.out", "w", stdout); // #endif cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; 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...