제출 #506653

#제출 시각아이디문제언어결과실행 시간메모리
506653abc864197532Longest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
58 ms4144 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define X first #define Y second #define pii pair<int, int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #define test(x...) abc("[" + string(#x) + "]", x); const int N = 200000; int main () { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector <int> a(n), k(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> k[i]; if (n <= 5000) { vector <int> dp(n, 0), bck(n, -1); for (int i = 0; i < n; ++i) { dp[i] = 1; for (int j = 0; j < i; ++j) { if (__builtin_popcount(a[j] & a[i]) == k[i] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; bck[i] = j; } } } int mx = max_element(all(dp)) - dp.begin(); cout << dp[mx] << endl; vector <int> ans; while (mx != -1) { ans.pb(mx + 1); mx = bck[mx]; } reverse(all(ans)); printv(all(ans)); } else { vector <int> dp(n, 0), bck(n, -1); vector <pii> tmp(1 << 8, mp(-1, 0)); for (int i = 0; i < n; ++i) { dp[i] = 1; for (int j = 0; j < 1 << 8; ++j) { if (__builtin_popcount(j & a[i]) == k[i] && dp[i] < tmp[i].X) { tie(dp[i], bck[i]) = tmp[i]; } } tmp[a[i]] = max(tmp[a[i]], mp(dp[i] + 1, i)); } int mx = max_element(all(dp)) - dp.begin(); cout << dp[mx] << endl; vector <int> ans; while (mx != -1) { ans.pb(mx + 1); mx = bck[mx]; } reverse(all(ans)); printv(all(ans)); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...