제출 #1110839

#제출 시각아이디문제언어결과실행 시간메모리
1110839KK_1729Longest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6056 ms4428 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define pb push_back #define all(a) a.begin(), a.end() #define endl "\n" void printVector(vector<int> a){ for (auto x: a) cout << x << " "; cout << endl; } void solve(){ int n; cin >> n; vector<int> a(n); FOR(i,0,n) cin >> a[i]; vector<int> k(n); FOR(i,0,n) cin >> k[i]; vector<int> dp(n, 1); vector<int> prev(n); int best = 0; int c = 0; FOR(i,0,n){ prev[i] = i; FOR(j,0,i){ if (__builtin_popcount(a[i]&a[j]) == k[i]){ if (dp[j]+1 > dp[i]){ dp[i] = dp[j]+1; prev[i] = j; } } } if (dp[i] > best){ best = dp[i]; c = i; } } cout << best << endl; vector<int> ans = {}; while (prev[c] != c){ ans.pb(c+1); c = prev[c]; } ans.pb(c+1); reverse(all(ans)); printVector(ans); } int32_t main(){ ios::sync_with_stdio(false);cin.tie(nullptr); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...