Submission #502742

#TimeUsernameProblemLanguageResultExecution timeMemory
502742tox1c_kidLongest beautiful sequence (IZhO17_subsequence)C++17
23 / 100
416 ms262148 KiB
#include <iostream> #include <iomanip> #include <fstream> #include <cstdio> #include <sstream> #include <cassert> #include <vector> #include <numeric> #include <string> #include <bitset> #include <cmath> #include <complex> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <random> #include <chrono> #include <ctime> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/assoc_container.hpp> /* ⠄⠄⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄ ⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄ ⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄ ⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄ ⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰ ⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤ ⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗ ⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄ ⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄ ⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄ ⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄ ⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄ ⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄ ⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴ ⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿ */ using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef double db; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define all(x) (x).begin(), (x).end() mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cout << "\n"; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); } #ifdef CLOWN #define dbg(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); #else #define dbg(...); #endif int test = 0; void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void solve() { int n; cin >> n; vector<int> dp(n); vector<int> a(n); vector<int> k(n); for (int i =0 ; i < n; i++) cin >> a[i]; for (int j = 0; j < n; j++) cin >> k[j]; vector<int> p(n, -1); int id = 0, mx = 0; vector<int> used(256 + 1, -1); dbg(dp) if (n <= 5000) { for (int i = 0; i < n; i++) { // now dp[i] = 1; for (int j = 0; j < i; j++) { // prev if (__builtin_popcount(a[i] & a[j]) != k[i]) continue; if (dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; p[i] = j; } } if (dp[i] > mx) { mx = dp[i]; id = i; } } vector<int> ans; while (id != -1) { ans.push_back(id); id = p[id]; } reverse(all(ans)); cout << ans.size() << "\n"; for (auto i : ans) { cout << i + 1 << " "; } } else { dp[0] = 1; used[a[0]] = 0; for (int i = 1; i < n; i++) { // now for (int j = 0; j <= (1 << 8); j++) { // prev if (__builtin_popcount(a[i] & j) == k[i] && used[j] != -1) { if (dp[i] < dp[used[j]] + 1) { dp[i] = dp[used[j]] + 1; p[i] = used[j]; } } if (used[a[i]] == -1) { used[a[i]] = i; continue; } if (dp[i] > dp[used[a[i]]]) { used[a[i]] = i; } } } for (int i = 0; i < n; i++) { if (dp[i] > mx) { mx = dp[i]; id = i; } } vector<int> ans; while (id != -1) { ans.push_back(id); id = p[id]; } reverse(all(ans)); cout << ans.size() << "\n"; for (auto i : ans) cout << i + 1 << " "; } } int32_t main() { #ifdef CLOWN freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; fastio(); if (test) cin >> t; while (t--) { solve(); } 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...