제출 #340335

#제출 시각아이디문제언어결과실행 시간메모리
340335TosicLongest beautiful sequence (IZhO17_subsequence)C++14
23 / 100
54 ms1772 KiB
#include <bits/stdc++.h> #define maxn 100010 using namespace std; int n, a[maxn], k[maxn], ans; pair<int, int> dp[maxn]; int main(){ ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cin >> n; for(int i = 0; i < n; ++i){ cin >> a[i]; } for(int i = 0; i < n; ++i){ cin >> k[i]; } if(n <= 5000){ for(int i = 0; i < n; ++i){ dp[i] = {1, -1}; for(int j = 0; j < i; ++j){ if(__builtin_popcount(a[i]&a[j]) == k[i]){ if(dp[j].first+1 > dp[i].first){ dp[i] = dp[j]; dp[i].second = j; dp[i].first = dp[j].first+1; } } } } pair<int, int> ans = {1, -1}; int idx = 0; for(int i = 0; i < n; ++i){ ans = max(ans, dp[i]); if(ans == dp[i]){ idx = i; } } vector<int> res; while(true){ res.push_back(idx+1); if(ans.second == -1){ break; } idx = ans.second; ans = dp[ans.second]; } reverse(res.begin(), res.end()); cout << res.size() << '\n'; for(auto tmp:res){ cout << tmp<<'\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...