제출 #1006668

#제출 시각아이디문제언어결과실행 시간메모리
1006668Muaath_5Longest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6071 ms1628 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int N = 1e5+1; int n, a[N], k[N]; int dp[N]; int prv[N]; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin >> n; for (int i = 1; i <= n; cin >> a[i++]); for (int i = 1; i <= n; cin >> k[i++]); for (int i = 1; i <= n; i++) { dp[i] = 1; for (int j = 1; j < i; j++) { if (__builtin_popcount(a[i]&a[j]) == k[i]) { if (dp[j]+1 > dp[i]) { dp[i] = dp[j]+1; prv[i] = j; } } } } int idx = max_element(dp, dp+n+1)-dp; vector<int> lis; while (idx) { lis.push_back(idx); idx = prv[idx]; } reverse(lis.begin(), lis.end()); cout << lis.size() << '\n'; for (int i:lis) cout << i << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...