Submission #1014978

#TimeUsernameProblemLanguageResultExecution timeMemory
1014978ThunnusLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
6043 ms4188 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define int i64 #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int, int> #define fi first #define se second #define sz(x) (int)(x).size() signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; pii best = {1, 0}; cin >> n; vi a(n), k(n); for(int &i : a) cin >> i; for(int &i : k) cin >> i; vi prev(n), dp(n, 1), ans; iota(prev.begin(), prev.end(), 0); for(int i = 1; i < n; i++){ for(int j = 0; j < i; j++){ if(__builtin_popcount(a[j] & a[i]) == k[i] && dp[j] + 1 > dp[i]){ dp[i] = dp[j] + 1; prev[i] = j; if(dp[i] > best.fi) best = {dp[i], i}; } } } while(prev[best.se] != best.se){ ans.emplace_back(best.se + 1); best.se = prev[best.se]; } ans.emplace_back(best.se + 1); reverse(ans.begin(), ans.end()); cout << best.fi << "\n"; for(int i : ans){ cout << i << " "; } 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...