# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
810310 | marvinthang | Longest beautiful sequence (IZhO17_subsequence) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*************************************
* author: marvinthang *
* created: 05.08.2023 13:16:34 *
*************************************/
#include "bitseq.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i-- > 0; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; }
// end of template
const int MAX = 1e5 + 5;
pair <int, int> ff[MASK(10)][MASK(10)][11], dp[MAX];
vector <int> bitseq(vector <int> a, vector <int> c) {
int n = a.size();
REP(i, n) {
int first = a[i] >> 10;
int last = a[i] & (MASK(10) - 1);
REP(j, MASK(10)) {
int v = c[i] - __builtin_popcount(first & j);
if (v >= 0 && v <= 10) maximize(dp[i], ff[j][last][v]);
}
++dp[i].fi;
REP(j, MASK(10)) maximize(ff[first][j][__builtin_popcount(last & j)], pair {dp[i].fi, -i});
}
vector <int> res;
int p = max_element(dp, dp + n) - dp;
while (true) {
res.push_back(p + 1);
if (dp[p].fi == 1) break;
p = -dp[p].se;
}
reverse(ALL(res));
return res;
}
#ifdef LOCAL
#include "bitseq.h"
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
int main() {
file("bitseq");
int n;
assert(scanf("%d", &n) == 1);
vector<int> a(n);
for (int i = 0; i < n; i++) {
assert(scanf("%d", &a[i]) == 1);
}
vector<int> c(n);
for (int i = 0; i < n; i++) {
assert(scanf("%d", &c[i]) == 1);
}
fclose(stdin);
std::vector<int> answer = bitseq(a, c);
printf("%lu\n", answer.size());
for (size_t i = 0; i < answer.size(); i++) {
printf("%d", answer[i]);
if(i + 1 < answer.size()) {
printf(" ");
}
}
fclose(stdout);
return 0;
}
#endif