Submission #884652

#TimeUsernameProblemLanguageResultExecution timeMemory
884652smaxLongest beautiful sequence (IZhO17_subsequence)C++17
40 / 100
6045 ms126484 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) #else #define DEBUG(...) 6 #endif template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";} template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr> ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";} template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";} template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n), k(n); for (int &x : a) cin >> x; for (int &x : k) cin >> x; vector<pair<int, int>> dp(n); vector trans(1 << 10, vector(1 << 10, vector<pair<int, int>>(11))); for (int i=0; i<n; i++) { int top = a[i] >> 10, bot = a[i] & ((1 << 10) - 1); for (int mask=0; mask<1<<10; mask++) { int c = k[i] - __builtin_popcount(mask & top); if (0 <= c && c <= 10) dp[i] = max(dp[i], trans[mask][bot][c]); } dp[i].first++; for (int mask=0; mask<1<<10; mask++) { int c = __builtin_popcount(mask & bot); trans[top][mask][c] = max(trans[top][mask][c], {dp[i].first, i}); } } int i = int(max_element(dp.begin(), dp.end()) - dp.begin()); vector<int> ret; while (dp[i].first > 1) { ret.push_back(i); i = dp[i].second; } ret.push_back(i); reverse(ret.begin(), ret.end()); cout << ret.size() << "\n"; for (int x : ret) cout << x + 1 << " "; cout << "\n"; 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...