QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#953601 | #33. Cat in a tree | zjs | 100 ✓ | 25ms | 15588kb | C++20 | 25.5kb | 2025-03-27 21:31:49 | 2025-03-27 21:31:50 |
Judging History
answer
/**
* code generated by JHelperX
* More info: https://github.com/GoBigorGoHome/JHelperX
* @author zjs
*/
#if not defined LOCAL and not defined NDEBUG
#define NDEBUG
#endif
#if not defined LOCAL
#define debug(...)
#endif
extern const bool show_all_failed_tests = false;
extern const bool compare_real_numbers = false;
//#define INTERACTIVE_MODE //对于交互题,取消此行注释。
//
// Created by zjsdu on 5/28/2020.
//
#ifndef JHELPER_EXAMPLE_PROJECT_LIBRARY_ALIAS_HPP_
#define JHELPER_EXAMPLE_PROJECT_LIBRARY_ALIAS_HPP_
#include <string>
#include <cassert>
#include <queue>
#ifndef JHELPER_EXAMPLE_PROJECT_LIBRARY_IO_HPP_
#define JHELPER_EXAMPLE_PROJECT_LIBRARY_IO_HPP_
#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
//
// Created by zjsdu on 10/22/2020.
//
#ifndef JHELPER_EXAMPLE_PROJECT_TASKS_TYPE_TRAITS_HPP_
#define JHELPER_EXAMPLE_PROJECT_TASKS_TYPE_TRAITS_HPP_
#include <type_traits>
#if __cplusplus >= 201703L
template<typename T> T type();// no definition
template<typename Container> auto value_type_of_() {
if constexpr (std::is_array_v<Container>)
return type<std::remove_extent_t<Container>>();
else
return type<typename Container::value_type>();
}
template<typename Container>
using value_type_of =
decltype(value_type_of_<std::remove_reference_t<Container>>());
#else
template <typename Container>
struct value_type_of_impl // default, non-array
{
using type = typename Container::value_type;
};
template <typename T, std::size_t N>
struct value_type_of_impl<T[N]> // arrays
{
using type = T;
};
template <typename Container>
using value_type_of = typename value_type_of_impl<Container>::type;
#endif
// Source: https://foonathan.net/2020/10/iife-metaprogramming/
#if __cplusplus >= 201703L
namespace is_iterable_impl {
using std::begin;
using std::end;
template<typename T>
using check_specs = std::void_t<
std::enable_if_t<
std::is_same<decltype(begin(std::declval<T &>())),// has begin()
decltype(end(std::declval<T &>())) // has end()
>::value>,// ... begin() and end() are the same type ...
decltype(*begin(std::declval<T &>()))>;// ... which can be dereferenced
template<typename, typename = void> struct is_iterable : std::false_type {};
// specialization
template<class T> struct is_iterable<T, check_specs<T>> : std::true_type {};
}// namespace is_iterable_impl
template<class T> using is_iterable = is_iterable_impl::is_iterable<T>;
template<typename T> constexpr bool is_iterable_v = is_iterable<T>::value;
// Source: https://stackoverflow.com/a/53429396/6793559
template<typename T>
using is_string =
std::disjunction<std::is_same<char *, typename std::decay_t<T>>,
std::is_same<const char *, typename std::decay_t<T>>,
std::is_same<std::string, typename std::decay_t<T>>>;
template<typename T> constexpr bool is_string_v = is_string<T>::value;
// Source: https://stackoverflow.com/a/57812868/6793559
template<template<typename...> typename Target, typename Aux, typename... Ts>
struct is_specialized_for_impl : std::false_type {};
template<template<typename...> typename Target, typename... Args>
struct is_specialized_for_impl<Target, decltype(sizeof(Target<Args...>)),
Args...> : std::true_type {};
template<template<typename...> typename Target, typename... Args>
using is_specialized_for =
is_specialized_for_impl<Target, std::size_t, Args...>;
template<template<typename...> typename Target, typename... Args>
constexpr bool is_specialized_for_v =
is_specialized_for<Target, Args...>::value;
template<typename T>
using is_tuple_like = is_specialized_for<std::tuple_size, T>;
template<typename T> constexpr bool is_tuple_like_v = is_tuple_like<T>::value;
template<typename T, typename = void> struct remove_all_extents_ {
typedef std::remove_reference_t<T> type;
};
template<typename T>
struct remove_all_extents_<T, std::void_t<decltype(std::declval<T>()[0])>> {
typedef
typename remove_all_extents_<decltype(std::declval<T>()[0])>::type type;
};
template<typename T, typename = void>
struct rank_ : public std::integral_constant<std::size_t, 0> {};
template<typename T>
struct rank_<T, std::void_t<decltype(std::declval<T>()[0])>>
: public std::integral_constant<
std::size_t, rank_<decltype(std::declval<T>()[0])>::value + 1> {};
#endif
#endif// JHELPER_EXAMPLE_PROJECT_TASKS_TYPE_TRAITS_HPP_
struct fast_ios {
fast_ios() {
#ifndef INTERACTIVE_MODE
std::cin.tie(nullptr);
#endif
std::ios::sync_with_stdio(false);
std::cout.precision(15);
std::cout << std::fixed;
};
} const fast_ios_;
namespace io {
template<typename T, typename U>
std::ostream &operator<<(std::ostream &out, const std::pair<T, U> &p);
template<typename... Ts>
std::istream &operator>>(std::istream &in, std::tuple<Ts...> &t);
template<typename... Ts>
std::ostream &operator<<(std::ostream &, const std::tuple<Ts...> &);
template<typename T, typename U>
std::istream &operator>>(std::istream &in, std::pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template<typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &vec) {
for (auto &x : vec)
stream >> x;
return stream;
}
#if __cplusplus >= 201703L // fold expressions require C++17
template<typename... Ts>
std::istream &operator>>(std::istream &in, std::tuple<Ts...> &t) {
std::apply([&in](auto &...args) { ((in >> args), ...); }, t);
return in;
}
template<class... Args>
void scan(Args &...args) {
((std::cin >> args), ...);
}
template<typename Container,
typename = std::enable_if_t<std::conjunction_v<
is_iterable<Container>, std::negation<is_string<Container>>>>>
std::ostream &operator<<(std::ostream &out, const Container &container) {
using std::begin;
using value_type =
std::remove_reference_t<decltype(*begin(std::declval<Container &>()))>;
constexpr char delimiter =
is_iterable_v<value_type> or is_tuple_like_v<value_type> ? '\n' : ' ';
bool first = true;
for (auto &element : container) {
if (first)
first = false;
else
out << delimiter;
out << element;
}
return out;
}
// Source: https://en.cppreference.com/w/cpp/utility/apply
template<typename... Ts>
std::ostream &operator<<(std::ostream &out, const std::tuple<Ts...> &theTuple) {
std::apply(
[&out](Ts const &...tupleArgs) {
std::size_t n{0};
((out << tupleArgs << (++n != sizeof...(Ts) ? " " : "")), ...);
},
theTuple);
return out;
}
#endif
template<typename T, typename U>
std::ostream &operator<<(std::ostream &out, const std::pair<T, U> &p) {
out << p.first << ' ' << p.second;
return out;
}
template<typename T>
std::ostream &operator<<(std::ostream &out,
const std::vector<std::vector<T>> &t) {
bool is_first = true;
for (const auto &row : t) {
if (is_first)
is_first = false;
else
out << '\n';
out << row;
}
return out;
}
std::ostream &operator<<(std::ostream &os, unsigned __int128 n) {
using u64 = unsigned long long;
static const u64 B = 1e19;
if (n < B)
os << (u64) n;
else
os << n / B << std::setfill('0') << std::setw(19) << n % B;
return os;
}
std::ostream &operator<<(std::ostream &os, __int128 n) {
if (n < 0) {
os << '-' << (unsigned __int128) -n;
} else {
os << (unsigned __int128) n;
}
return os;
}
#if __cplusplus >= 201703L
template<typename... Args>
void pt(Args &&...args) {
((std::cout << args << ' '), ...);
}
template<typename First, typename... Args>
void pl(const First &first, const Args &...args) {
std::cout << first;
((std::cout << ' ' << args), ...);
std::cout << '\n';
}
template<typename... Args>
void pn(const Args &...args) {
((std::cout << args << '\n'), ...);
}
#endif
}// namespace io
#endif// JHELPER_EXAMPLE_PROJECT_LIBRARY_IO_HPP_
//
// Created by zjsdu on 10/26/2020.
//
#ifndef JHELPER_EXAMPLE_PROJECT_LIBRARY_NDARRAY_HPP_
#define JHELPER_EXAMPLE_PROJECT_LIBRARY_NDARRAY_HPP_
template<typename T, unsigned Dimension> struct ndvec {
using type = std::vector<typename ndvec<T, Dimension - 1>::type>;
};
template<typename T> struct ndvec<T, 0> { using type = T; };
// arbitrary-dimensional array that allows non-constexpr extents.
// Usage: ndarray<dimension, value_type> arr(extents..., init_value);
// An initial value for all array items can be specified if all extensions are
// specified.
// Examples:
// ndarray<2, int> a(2, 3, -1);
// ndarray<3, int> b(2, 3, 4);
// ndarray<3, int> c(2, 3);
template<unsigned dimension, typename T>
class ndarray : public ndvec<T, dimension>::type {
using base_type = typename ndvec<T, dimension>::type;
using value_type = typename base_type::value_type;
using base_type::base_type;
public:
template<typename... Args>
ndarray(unsigned d, Args... args)
: std::vector<value_type>(d, ndarray<dimension - 1, T>(args...)) {}
};
template<typename T> class ndarray<1, T> : public std::vector<T> {
using std::vector<T>::vector;
};
#endif// JHELPER_EXAMPLE_PROJECT_LIBRARY_NDARRAY_HPP_
//
// Created by zjsdu on 2/9/2021.
//
#ifndef JHELPER_EXAMPLE_PROJECT_LIBRARY_MACROS_H_
#define JHELPER_EXAMPLE_PROJECT_LIBRARY_MACROS_H_
#define CALL_WITH_EXPANDED_ARGS(function, ...) function(__VA_ARGS__)
#define JOIN_IMPL(arg1, arg2) arg1##arg2
#define JOIN(arg1, arg2) JOIN_IMPL(arg1, arg2)
#define EXPAND_1(...) __VA_ARGS__
#define EXPAND_4(...) EXPAND_1(EXPAND_1(EXPAND_1(__VA_ARGS__)))
#define EXPAND_13(...) EXPAND_4(EXPAND_4(EXPAND_4(__VA_ARGS__)))
#define PAUSE
#define COMMA() ,
#define TERMINATE(...)
#define SELECT_SECOND_ARG(arg1, arg2, ...) arg2
#define CONDITIONAL(peek, arg1, arg2) \
CALL_WITH_EXPANDED_ARGS(SELECT_SECOND_ARG, COMMA peek arg1, arg2)
#define TERMINATE_OR(peek, arg) CONDITIONAL(peek, TERMINATE, arg)
#define FOR_EACH_2_IMPL0(function, arg1, arg2, peek, ...) \
function(arg1, arg2) TERMINATE_OR(peek, FOR_EACH_2_IMPL1) \
PAUSE(function, peek, __VA_ARGS__)
#define FOR_EACH_2_IMPL1(function, arg1, arg2, peek, ...) \
function(arg1, arg2) TERMINATE_OR(peek, FOR_EACH_2_IMPL0) \
PAUSE(function, peek, __VA_ARGS__)
#define FOR_EACH_2(function, ...) \
EXPAND_13(FOR_EACH_2_IMPL0(function, __VA_ARGS__, ()))
#endif// JHELPER_EXAMPLE_PROJECT_LIBRARY_MACROS_H_
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using vi = std::vector<int>;
using vs = std::vector<std::string>;
using pii = std::pair<int, int>;
using pli = std::pair<ll, int>;
using pil = std::pair<int, ll>;
using pll = std::pair<ll, ll>;
using vii = std::vector<pii>;
template<typename T>
using pq = std::priority_queue<T>;
template<typename T>
using min_pq = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename... Ts> using vt = std::vector<std::tuple<Ts...>>;
template<typename T> using vv = ndarray<2, T>;
template<typename T> struct range_tuple {
const T &ref = beg;
T beg;
const T end;
range_tuple(T b, T e) : beg(b), end(e) {}
};
#define rng4(i, a, b, c) \
for (auto &&[i, JOIN(iter_, __LINE__), JOIN(end_, __LINE__)] = \
range_tuple<std::common_type_t<decltype(a), decltype(b)>>(a, b); \
i < JOIN(end_, __LINE__); JOIN(iter_, __LINE__) += c)
#define rng3(i, a, b) rng4(i, a, b, 1)
#define rng2(i, n) rng3(i, 0, n)
#define GET4(_1, _2, _3, _4, NAME, ...) NAME
#define rng(...) GET4(__VA_ARGS__, rng4, rng3, rng2)(__VA_ARGS__)
#define up4(i, a, b, c) rng (i, a, b + 1, c)
#define up3(i, a, b) up4(i, a, b, 1)
#define up(...) GET4(__VA_ARGS__, up4, up3, NO_IMPL)(__VA_ARGS__)
#define down4(i, b, a, c) \
for (auto &&[i, JOIN(iter_, __LINE__), JOIN(end_, __LINE__)] = \
range_tuple<std::common_type_t<decltype(a), decltype(b)>>(b, a); \
i >= JOIN(end_, __LINE__); JOIN(iter_, __LINE__) -= c)
#define down3(i, b, a) down4(i, b, a, 1)
#define down(...) GET4(__VA_ARGS__, down4, down3, NO_IMPL)(__VA_ARGS__)
#define rep(n) \
for (auto JOIN(_iter_, __LINE__) = n; JOIN(_iter_, __LINE__) > 0; \
--JOIN(_iter_, __LINE__))
#define FOR_LAST_OPERATION_IMPL(arg1, arg2) arg1] : arg2
#define FOR_NORMAL_OPERATION_IMPL(arg1, arg2) arg1,
#define FOR_IMPL0(arg1, arg2, peek, ...) \
CONDITIONAL(peek, FOR_LAST_OPERATION_IMPL, FOR_NORMAL_OPERATION_IMPL) \
(arg1, arg2) TERMINATE_OR(peek, FOR_IMPL1) PAUSE(arg2, peek, __VA_ARGS__)
#define FOR_IMPL1(arg1, arg2, peek, ...) \
CONDITIONAL(peek, FOR_LAST_OPERATION_IMPL, FOR_NORMAL_OPERATION_IMPL) \
(arg1, arg2) TERMINATE_OR(peek, FOR_IMPL0) PAUSE(arg2, peek, __VA_ARGS__)
#define FOR_IMPL3(arg1, arg2, peek, ...) \
CONDITIONAL(peek, for (auto && arg1 : arg2), \
for (auto && [EXPAND_13(FOR_IMPL0(arg1, arg2, peek, __VA_ARGS__))))
#define FOR(...) FOR_IMPL3(__VA_ARGS__, ())
#define ALL(x) std::begin(x), std::end(x)
// hat off to 300iq
#define RALL(x) std::rbegin(x), std::rend(x)
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define ep emplace
#define SZ(x) (int) (x).size()
#define rp(...) return pl(__VA_ARGS__)
#define rpn(...) return pn(__VA_ARGS__)
#define adv(i, n) \
for (auto JOIN(_n_, __LINE__) = n; i < JOIN(_n_, __LINE__); ++i)
#define radv(i, n) \
for (auto JOIN(_n_, __LINE__) = n; i > JOIN(_n_, __LINE__); --i)
#define INT(...) \
int __VA_ARGS__; \
io::scan(__VA_ARGS__)
#define LL(...) \
long long __VA_ARGS__; \
io::scan(__VA_ARGS__)
#define STR(...) \
std::string __VA_ARGS__; \
io::scan(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
io::scan(__VA_ARGS__)
#define NL \
[] { \
std::cout << '\n'; \
}()
#define RI \
([] { \
int x; \
std::cin >> x; \
return x; \
})()
#define READ_VI(NAME, LEN) \
std::vector<int> NAME(LEN); \
io::scan(NAME);
#define VI(...) FOR_EACH_2(READ_VI, __VA_ARGS__)
#define READ_VII(NAME, LEN) \
std::vector<std::pair<int, int>> NAME(LEN); \
io::scan(NAME);
#define VII(...) FOR_EACH_2(READ_VII, __VA_ARGS__)
#define READ_VL(NAME, LEN) \
std::vector<long long> NAME(LEN); \
io::scan(NAME);
#define VL(...) FOR_EACH_2(READ_VL, __VA_ARGS__)
#define READ_VS(NAME, LEN) \
std::vector<std::string> NAME(LEN); \
io::scan(NAME);
#define VS(...) FOR_EACH_2(READ_VS, __VA_ARGS__)
#endif// JHELPER_EXAMPLE_PROJECT_LIBRARY_ALIAS_HPP_
#ifndef CP_UTILS
#define CP_UTILS
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <numeric>
#include <set>
#include <random>
#include <chrono>
inline void Yn(bool p) {
std::cout << (p ? "Yes\n" : "No\n");
}
inline void YN(bool p) {
std::cout << (p ? "YES\n" : "NO\n");
}
inline void yn(bool p) {
std::cout << (p ? "yes\n" : "no\n");
}
template<typename Container> Container inc(Container &&c) {
for (auto &e : c)
++e;
return std::forward<Container>(c);
}
template<typename Container> Container dec(Container &&c) {
for (auto &e : c)
--e;
return std::forward<Container>(c);
}
template<typename A, typename B>
bool chmin(A& a, const B& b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename A, typename B>
bool chmax(A& a, const B& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#if __cplusplus >= 201703L
template<typename A, typename B, typename... C>
bool chmin(A& a, const B& b, const C&... c) {
if (B res = std::min<B>({b, c...}); res < a) {
a = res;
return true;
}
return false;
}
template<typename A, typename B, typename... C>
bool chmax(A& a, const B& b, const C&... c) {
if (B res = std::max<B>({b, c...}); res > a) {
a = res;
return true;
}
return false;
}
#endif
template<typename T, typename U>
void append(T &container1, const U &container2) {
container1.insert(container1.end(), container2.begin(), container2.end());
}
template<typename T> int argmin(const std::vector<T> &a) {
return (int) (std::min_element(a.begin(), a.end()) - a.begin());
}
template<typename T> int argmax(const std::vector<T> &a) {
return (int) (std::max_element(a.begin(), a.end()) - a.begin());
}
template<typename Container> Container reverse(Container &&c) {
std::reverse(std::begin(c), std::end(c));
return std::forward<Container>(c);
}
template<typename Sequence> Sequence rev_copy(Sequence a) {
std::reverse(std::begin(a), std::end(a));
return a;
}
template<typename Sequence> Sequence uniq(Sequence &&s) {
std::sort(std::begin(s), std::end(s));
s.erase(std::unique(std::begin(s), std::end(s)), std::end(s));
return std::forward<Sequence>(s);
}
template<typename Container> auto max(const Container &c) {
assert(c.size() > 0);
return *std::max_element(std::begin(c), std::end(c));
}
template<typename Container> auto min(const Container &c) {
assert(c.size() > 0);
return *std::min_element(std::begin(c), std::end(c));
}
template<typename Array, typename Value> auto lb(Array &a, Value v) {
return std::lower_bound(std::begin(a), std::end(a), v);
}
template<typename Array, typename Value> auto ub(Array &a, Value v) {
return std::upper_bound(std::begin(a), std::end(a), v);
}
template<typename Array, typename Value, typename Compare>
auto lb(Array &a, Value v, Compare compare) {
return std::lower_bound(std::begin(a), std::end(a), v, compare);
}
template<typename Array, typename Value, typename Compare>
auto ub(Array &a, Value v, Compare compare) {
return std::upper_bound(std::begin(a), std::end(a), v, compare);
}
template<typename Array, typename Value> int lbi(const Array &a, Value v) {
return int(lb(a, v) - std::begin(a));
}
template<typename Iter, typename Value> int lbi(Iter beg, int count, Value v) {
assert(count > 0);
return int(std::lower_bound(beg, beg + count, v) - beg);
}
template<typename Iter, typename Value> int ubi(Iter beg, int count, Value v) {
assert(count > 0);
return int(std::upper_bound(beg, beg + count, v) - beg);
}
template<typename Array, typename Value> int ubi(const Array &a, Value v) {
return int(ub(a, v) - std::begin(a));
}
template<typename Container>
Container iota(Container &&c, value_type_of<Container> v) {
std::iota(std::begin(c), std::end(c), v);
return std::forward<Container>(c);
}
template<typename T, typename Comp>
std::vector<int> argsort(const std::vector<T> &array, Comp comp) {
std::vector<int> res(array.size());
std::iota(res.begin(), res.end(), 0);
std::stable_sort(res.begin(), res.end(), [&array, comp](int i, int j) {
return comp(array[i], array[j]);
});
return res;
}
template<typename T> std::vector<int> argsort(const std::vector<T>& array) {
std::vector<int> res(array.size());
std::iota(res.begin(), res.end(), 0);
std::stable_sort(res.begin(), res.end(),
[&array](int i, int j) { return array[i] < array[j]; });
return res;
}
#if __cplusplus >= 201703L
template<typename Container, typename Compare = void *>
Container sort(Container &&c, Compare comp = nullptr) {
if constexpr (std::is_same_v<Compare, void *>)
std::sort(std::begin(c), std::end(c));
else
std::sort(std::begin(c), std::end(c), comp);
return std::forward<Container>(c);
}
#endif
template<typename T> struct reversion_wrapper { T &iterable; };
template<typename T> auto begin(reversion_wrapper<T> w) {
using std::rbegin;
return rbegin(w.iterable);
}
template<typename T> auto end(reversion_wrapper<T> w) {
using std::rend;
return rend(w.iterable);
}
template<typename T> reversion_wrapper<T> rev_view(T &&iterable) {
return {std::forward<T>(iterable)};
}
/// @return nearest integer not less than the quotient x/y.
template<typename T, typename U> T qceil(T x, U y) {
assert(y > 0);
T q = x / y;
return q + (q * y < x);
}
/// @return nearest integer not greater than the quotient x/y.
template<typename T, typename U> T qfloor(T x, U y) {
assert(y > 0);
T q = x / y;
return q - (q * y > x);
}
template<typename T, typename U> std::pair<T, U> divmod(T x, U y) {
assert(y > 0);
T q = qfloor(x, y);
return {q, x - q * y};
};
/// @return nearest multiple of y not less than x.
template<typename T, typename U> T mceil(T x, U y) {
assert(y > 0);
return qceil(x, y) * y;
}
/// @return nearest multiple of y not greater than x.
template<typename T, typename U> T mfloor(T x, U y) {
assert(y > 0);
return qfloor(x, y) * y;
}
// recursive lambda: https://stackoverflow.com/a/40873657/6793559
#if __cplusplus >= 201703L
template<class F> struct y_combinator {
F f;
template<class... Args> decltype(auto) operator()(Args &&...args) {
return f(*this, std::forward<Args>(args)...);
}
};
template<class F> y_combinator(F) -> y_combinator<F>;
#endif
template<typename T> constexpr T INF = std::numeric_limits<T>::max() / 2;
/// @brief Usage: acc\<type_of_sum\>(array)
template<typename T, typename U> T acc(const U& array) {
return std::accumulate(std::begin(array), std::end(array), T(0));
}
template <typename T> T acc(const std::vector<T>& array) {
return std::accumulate(array.begin(), array.end(), T(0));
}
// maps values of a into 0, 1, 2, ..., preserving order.
template<typename T> std::vector<int> normalize(const std::vector<T> &a) {
assert(not a.empty());
int n = (int) a.size();
std::vector<int> I = argsort(a);
std::vector<int> b(a.size());
b[I[0]] = 0;
for (int i = 1; i < n; i++)
b[I[i]] = b[I[i - 1]] + (a[I[i - 1]] < a[I[i]]);
return b;
}
template<typename F>
long long binary_search(F check, long long ok, long long ng,
bool check_ok = true) {
if (check_ok)
assert(check(ok));
while (std::abs(ok - ng) > 1) {
long long x = ng + (ok - ng) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template<typename T, typename Int> int bit(T a, Int i) {
return a >> i & 1;
}
template <typename T, typename U>
std::vector<T> cumsum(const std::vector<U> &A, int off = 1) {
int N = (int) A.size();
std::vector<T> B(N + 1);
for (int i = 0; i < N; i++) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
#define popcnt(x) __builtin_popcountll((x))
// sign used in principle of inclusion-exclusion
int pie_sign(int s) {
assert(s >= 0);
return popcnt(s) & 1 ? -1 : 1;
}
#endif// CP_UTILS
using namespace io;
using namespace std;
void solve() {
int n, d;
cin >> n >> d;
vector<vector<int>> g(n);
// for (int i = 1; i < n - 1; i++) {
// int u, v;
// cin >> u >> v;
// --u;
// --v;
// g[u].push_back(v);
// g[v].push_back(u);
// }
for (int i = 1; i < n; i++) {
int p;
cin >> p;
g[p].push_back(i);
}
y_combinator tree_dp{[&](auto dfs, int u) -> pair<int, int> {
int min_d = d;
int sum = 0;
for (int v : g[u]) {
auto [a, b] = dfs(v);
if (min_d + b + 2 >= d) {
chmin(min_d, b);
sum += a;
} else {
sum += a - 1;
// If I'm smaller than you, I become you.
chmax(min_d, b);
}
}
min_d++;
if (min_d >= d)
return {sum + 1, 0};
return {sum, min_d};
}};
debug(tree_dp(0));
cout << tree_dp(0).first << '\n';
}
#include <iostream>
int main() {
#if defined FILE_IO and not defined LOCAL
freopen(FILE_IO ".in", "r", stdin);
freopen(FILE_IO ".out", "w", stdout);
#endif
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
10 2 0 0 2 2 0 3 4 7 2
output:
6
result:
ok single line: '6'
Test #2:
score: 11
Accepted
time: 0ms
memory: 3712kb
input:
10 3 0 0 2 1 4 4 3 1 7
output:
4
result:
ok single line: '4'
Test #3:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
12 1 0 0 1 3 1 0 2 1 3 2 2
output:
12
result:
ok single line: '12'
Test #4:
score: 11
Accepted
time: 0ms
memory: 3712kb
input:
12 4 0 0 1 2 0 0 4 7 7 9 10
output:
3
result:
ok single line: '3'
Test #5:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
14 2 0 1 2 3 0 1 5 1 4 0 3 11 9
output:
8
result:
ok single line: '8'
Test #6:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
14 4 0 0 2 3 4 2 6 3 6 9 3 3 2
output:
3
result:
ok single line: '3'
Test #7:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
16 2 0 0 0 1 2 3 2 6 6 0 4 11 0 12 2
output:
11
result:
ok single line: '11'
Test #8:
score: 11
Accepted
time: 0ms
memory: 3712kb
input:
16 3 0 0 0 3 2 2 0 2 8 4 6 11 8 3 5
output:
6
result:
ok single line: '6'
Test #9:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 1 0 0 2 2 2 1 0 3 1 4 2 2 12 0 6 10 13
output:
18
result:
ok single line: '18'
Test #10:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 5 0 0 2 1 0 2 6 5 8 5 0 8 5 4 12 7 10
output:
4
result:
ok single line: '4'
Test #11:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
18
result:
ok single line: '18'
Test #12:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
17
result:
ok single line: '17'
Test #13:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
17 1 0 1 1 0 0 1 2 0 1 0 2 1 2 2 2 2
output:
17
result:
ok single line: '17'
Test #14:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
17 2 0 1 0 1 1 0 2 1 2 1 1 0 1 2 0 0
output:
14
result:
ok single line: '14'
Test #15:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 5 0 0 1 1 0 1 2 2 2 1 0 0 1 0 1 1 0
output:
1
result:
ok single line: '1'
Test #16:
score: 11
Accepted
time: 1ms
memory: 3584kb
input:
18 1 0 1 2 0 1 0 4 0 2 3 0 3 2 1 3 4 2
output:
18
result:
ok single line: '18'
Test #17:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 2 0 0 0 1 2 2 3 3 1 3 4 1 1 4 2 4 0
output:
13
result:
ok single line: '13'
Test #18:
score: 11
Accepted
time: 0ms
memory: 3584kb
input:
18 3 0 1 1 3 1 4 2 1 0 2 0 0 1 1 3 0 3
output:
5
result:
ok single line: '5'
Test #19:
score: 11
Accepted
time: 1ms
memory: 3712kb
input:
18 6 0 0 2 3 4 3 3 1 6 1 2 0 2 0 5 2 4
output:
2
result:
ok single line: '2'
Test #20:
score: 11
Accepted
time: 0ms
memory: 3712kb
input:
18 7 0 1 0 3 2 0 6 3 4 4 3 2 6 3 6 0 0
output:
1
result:
ok single line: '1'
Subtask #2:
score: 40
Accepted
Dependency #1:
100%
Accepted
Test #21:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1500 1000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
2
result:
ok single line: '2'
Test #22:
score: 40
Accepted
time: 0ms
memory: 3584kb
input:
500 1 0 1 1 1 1 5 5 2 4 4 10 0 0 11 12 6 13 5 17 2 13 12 19 12 8 7 18 5 9 10 15 1 25 21 7 32 29 14 22 12 34 13 1 10 0 20 4 6 44 38 19 12 9 17 20 51 5 3 23 46 39 25 7 42 37 55 13 14 30 46 9 71 47 55 61 43 39 1 76 0 49 8 80 51 51 71 55 44 79 25 80 24 68 15 41 88 72 76 72 38 83 94 88 69 17 9 49 75 64 3...
output:
500
result:
ok single line: '500'
Test #23:
score: 40
Accepted
time: 0ms
memory: 3712kb
input:
500 5 0 1 2 0 3 5 0 2 0 3 10 1 3 5 13 8 8 16 16 4 17 5 1 17 6 1 17 9 20 0 27 27 1 14 24 30 17 5 37 37 9 33 7 20 39 24 29 20 33 19 32 26 13 33 31 21 31 11 20 50 35 34 16 47 17 5 48 55 60 66 57 43 10 68 69 69 34 75 27 41 3 56 8 32 41 85 55 70 5 57 48 61 41 78 19 12 85 73 62 18 79 95 47 39 61 67 88 18 ...
output:
89
result:
ok single line: '89'
Test #24:
score: 40
Accepted
time: 0ms
memory: 3584kb
input:
500 10 0 1 1 0 1 0 6 6 8 1 4 0 10 0 13 8 11 16 18 1 17 7 21 22 1 22 9 26 1 4 1 21 5 18 6 7 35 4 31 5 38 36 31 37 25 17 8 28 36 12 26 20 9 11 20 42 38 17 29 42 29 38 28 39 46 39 3 46 22 16 34 25 14 3 21 73 62 77 78 29 43 3 25 48 3 47 17 54 3 43 47 43 42 62 12 44 38 29 75 62 37 96 91 47 97 104 15 84 4...
output:
23
result:
ok single line: '23'
Test #25:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1000 1 0 0 0 2 0 4 3 4 4 2 9 4 1 12 2 12 7 12 13 1 12 20 17 5 8 3 7 0 11 18 28 2 29 26 34 24 5 24 22 38 30 0 30 19 17 9 45 32 14 47 42 29 47 5 2 1 44 23 16 48 3 51 28 44 16 24 31 8 49 0 6 12 39 6 13 2 74 77 0 25 78 67 43 83 32 22 69 38 57 32 62 23 12 22 53 85 88 91 3 4 42 96 93 20 59 44 59 102 95 86...
output:
1000
result:
ok single line: '1000'
Test #26:
score: 40
Accepted
time: 0ms
memory: 3712kb
input:
1000 5 0 0 1 1 2 3 0 2 0 1 6 3 10 13 14 1 12 0 2 0 0 16 0 14 13 11 1 4 2 15 21 10 24 4 0 18 16 29 24 2 38 40 17 31 17 30 8 18 12 49 16 47 31 52 53 10 41 28 39 57 20 49 43 1 46 27 59 38 7 37 24 38 36 13 59 34 25 31 63 36 4 32 72 9 17 4 80 87 63 20 68 43 42 64 80 8 88 2 24 68 6 41 34 68 63 66 92 32 93...
output:
191
result:
ok single line: '191'
Test #27:
score: 40
Accepted
time: 0ms
memory: 3584kb
input:
1000 10 0 0 1 2 2 2 4 2 3 9 10 5 7 3 4 6 7 2 8 16 9 5 4 3 17 17 23 10 11 26 15 30 20 32 27 12 5 29 10 15 22 9 40 19 30 1 23 33 16 5 0 5 18 18 5 48 5 50 27 39 35 60 54 11 29 25 43 13 62 29 48 39 13 49 44 66 52 65 54 29 66 15 32 35 76 7 53 40 57 7 7 77 82 83 43 31 28 85 69 1 9 72 32 29 53 57 5 94 57 6...
output:
44
result:
ok single line: '44'
Test #28:
score: 40
Accepted
time: 1ms
memory: 3712kb
input:
1500 12 0 1 2 0 4 2 0 4 6 2 3 10 4 2 12 2 10 1 5 7 7 10 3 10 0 20 1 15 24 25 0 10 30 13 0 14 24 20 7 37 25 6 20 34 37 0 27 28 25 26 28 8 2 25 50 19 19 55 33 26 53 1 53 23 20 23 27 36 17 63 22 39 10 22 26 68 62 26 1 56 11 1 51 12 19 84 42 59 65 73 9 61 63 65 27 44 34 85 31 79 98 72 60 57 92 10 53 45 ...
output:
41
result:
ok single line: '41'
Test #29:
score: 40
Accepted
time: 1ms
memory: 3712kb
input:
1500 5 0 0 2 2 3 0 5 0 0 6 2 8 0 12 8 0 2 5 4 4 4 0 0 10 16 4 26 27 10 17 23 21 5 24 27 6 22 28 2 38 24 11 38 25 19 20 22 35 21 7 6 42 21 19 30 30 56 10 23 31 5 35 49 25 2 28 31 56 43 65 55 62 15 45 10 70 30 56 67 28 35 56 4 25 42 34 41 76 12 81 66 66 8 57 47 80 75 14 68 97 12 58 10 75 86 64 101 104...
output:
293
result:
ok single line: '293'
Test #30:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1500 15 0 1 2 3 0 0 5 1 8 0 10 1 1 0 4 6 4 2 5 18 1 8 3 8 3 1 20 22 23 28 25 31 3 28 27 8 36 25 3 30 8 29 41 21 41 34 46 37 24 6 33 15 44 44 18 14 37 55 43 59 10 3 40 27 55 44 40 3 22 53 18 11 17 35 1 41 53 41 22 40 29 35 21 26 37 23 38 74 33 84 2 63 82 53 45 24 43 75 1 66 80 52 63 31 63 46 71 65 48...
output:
19
result:
ok single line: '19'
Test #31:
score: 40
Accepted
time: 1ms
memory: 3840kb
input:
1500 40 0 1 0 0 1 1 0 7 2 5 1 9 11 9 12 3 14 8 10 11 3 5 16 5 9 20 18 21 17 8 30 13 28 9 9 30 9 2 9 6 25 28 8 33 43 19 37 41 14 10 44 38 8 53 47 1 46 32 14 24 23 51 14 46 32 32 66 60 49 53 45 35 47 24 72 52 56 22 77 65 23 3 61 33 36 48 12 79 21 46 74 9 24 23 25 36 2 63 95 49 45 68 18 51 16 1 29 48 1...
output:
1
result:
ok single line: '1'
Test #32:
score: 40
Accepted
time: 1ms
memory: 3712kb
input:
1470 4 0 0 1 1 3 4 1 2 5 8 2 8 11 11 9 5 1 0 11 19 8 7 6 1 9 3 13 0 0 16 14 11 12 11 19 14 13 1 12 5 2 6 18 17 12 18 3 7 11 3 15 7 4 19 17 14 17 6 3 11 16 8 3 4 3 7 3 4 17 7 9 7 8 15 6 10 19 12 17 10 10 2 3 4 8 7 4 5 9 1 17 12 10 0 2 13 3 5 4 19 15 10 9 6 7 13 7 5 1 17 18 6 11 12 5 4 17 15 5 0 16 4 ...
output:
13
result:
ok single line: '13'
Test #33:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1470 10 0 1 2 1 0 3 2 6 5 6 0 0 7 7 3 2 13 5 12 1 5 18 9 5 18 0 18 9 10 19 1 14 15 12 7 7 6 3 8 5 2 17 3 10 6 2 2 12 1 17 19 9 6 7 3 10 18 5 12 5 10 11 2 8 3 19 6 15 19 13 17 6 9 5 1 1 2 10 7 17 4 18 14 7 18 12 0 12 13 17 14 12 12 13 11 0 2 18 9 8 6 3 16 5 9 10 0 13 0 10 6 5 17 0 4 8 3 6 18 14 15 5 ...
output:
1
result:
ok single line: '1'
Test #34:
score: 40
Accepted
time: 1ms
memory: 3840kb
input:
1400 10 0 1 1 1 3 3 1 0 7 1 5 3 8 0 6 11 6 13 4 5 5 17 4 6 13 21 3 24 19 21 21 13 0 29 5 2 29 23 15 4 14 24 33 15 44 4 5 13 7 10 46 24 25 15 48 43 16 0 57 35 43 35 33 50 20 46 21 4 6 1 1 42 8 44 8 17 30 70 40 0 8 3 80 10 14 26 66 2 45 1 46 73 0 8 89 25 4 60 51 26 61 50 85 29 38 17 84 88 30 44 1 64 1...
output:
5
result:
ok single line: '5'
Test #35:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1400 12 0 0 0 1 0 1 3 2 1 1 4 7 5 0 7 9 13 8 2 18 5 2 14 18 11 12 5 0 9 27 5 1 9 21 4 10 21 25 15 26 23 8 36 15 37 0 1 38 27 49 26 9 20 45 6 48 36 24 34 16 34 11 36 57 28 21 11 53 32 53 44 22 17 24 52 28 9 36 64 71 20 74 23 15 45 0 31 87 43 22 88 21 67 31 12 18 73 67 30 8 7 74 60 85 18 94 16 20 15 6...
output:
5
result:
ok single line: '5'
Test #36:
score: 40
Accepted
time: 0ms
memory: 3840kb
input:
1500 10 0 1 0 2 3 4 5 5 6 1 10 4 6 11 12 7 11 6 7 1 19 14 20 12 21 12 6 1 18 9 16 16 25 19 18 21 22 4 18 24 25 7 14 8 31 12 29 46 40 5 43 4 7 52 12 17 11 42 43 32 9 48 24 17 24 63 8 10 48 1 9 33 28 25 64 20 71 49 69 5 26 1 73 19 42 78 24 84 9 21 39 65 80 12 80 57 50 36 68 92 97 57 46 7 88 72 21 50 5...
output:
7
result:
ok single line: '7'
Test #37:
score: 40
Accepted
time: 1ms
memory: 3840kb
input:
1500 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 79 93 ...
output:
50
result:
ok single line: '50'
Test #38:
score: 40
Accepted
time: 1ms
memory: 3712kb
input:
1500 50 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
output:
7
result:
ok single line: '7'
Test #39:
score: 40
Accepted
time: 1ms
memory: 3840kb
input:
1500 70 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
output:
8
result:
ok single line: '8'
Test #40:
score: 40
Accepted
time: 0ms
memory: 3712kb
input:
1500 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
301
result:
ok single line: '301'
Subtask #3:
score: 49
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #41:
score: 49
Accepted
time: 15ms
memory: 11620kb
input:
190001 5 0 1 2 0 4 5 0 7 8 0 10 11 0 13 14 0 16 17 0 19 20 0 22 23 0 25 26 0 28 29 0 31 32 0 34 35 0 37 38 0 40 41 0 43 44 0 46 47 0 49 50 0 52 53 0 55 56 0 58 59 0 61 62 0 64 65 0 67 68 0 70 71 0 73 74 0 76 77 0 79 80 0 82 83 0 85 86 0 88 89 0 91 92 0 94 95 0 97 98 0 100 101 0 103 104 0 106 107 0 1...
output:
50462
result:
ok single line: '50462'
Test #42:
score: 49
Accepted
time: 10ms
memory: 7136kb
input:
100000 1 0 1 0 2 2 5 6 5 5 2 8 4 7 3 2 4 3 1 13 17 3 18 11 23 20 9 3 18 26 15 2 11 19 27 5 0 19 9 31 17 2 7 12 2 1 5 40 6 4 33 16 30 8 40 2 26 4 23 0 32 39 32 43 11 52 8 61 15 0 62 16 56 11 34 21 14 64 23 11 71 33 78 60 76 65 19 45 9 38 79 74 45 39 49 55 17 64 53 90 78 70 4 8 13 73 26 4 98 63 70 105...
output:
100000
result:
ok single line: '100000'
Test #43:
score: 49
Accepted
time: 11ms
memory: 7272kb
input:
100000 20 0 1 1 0 2 5 6 3 5 5 2 3 5 13 0 2 8 16 8 5 16 12 4 22 2 7 26 23 26 28 12 17 23 21 4 17 1 31 14 4 24 21 28 33 33 24 35 27 15 33 42 32 32 7 46 39 20 44 52 0 13 5 54 11 43 0 45 43 25 2 44 66 50 20 18 34 28 75 28 21 24 23 10 62 23 79 53 81 71 77 29 43 42 83 86 13 24 87 10 67 60 77 54 74 74 52 8...
output:
454
result:
ok single line: '454'
Test #44:
score: 49
Accepted
time: 12ms
memory: 7268kb
input:
100000 50 0 1 1 2 0 3 5 3 7 9 5 6 4 6 8 7 15 3 10 1 17 15 14 22 2 4 19 9 5 12 2 4 20 18 8 8 35 15 26 13 19 35 30 34 20 42 27 0 26 39 41 43 51 3 39 24 38 56 48 32 59 50 56 33 1 65 61 14 19 61 40 6 50 47 59 54 48 69 29 40 61 76 11 37 16 46 53 23 53 40 63 4 12 50 44 55 89 10 85 9 72 95 81 85 18 85 36 6...
output:
1
result:
ok single line: '1'
Test #45:
score: 49
Accepted
time: 11ms
memory: 7268kb
input:
100000 100 0 1 0 3 1 2 2 7 6 9 7 11 3 12 14 1 2 2 2 14 5 7 15 21 18 0 18 6 18 16 1 7 4 26 34 29 31 37 36 11 38 18 7 29 37 45 4 40 37 4 0 14 9 2 25 36 36 45 40 56 34 41 61 37 32 52 59 65 40 19 67 41 41 43 14 72 49 73 69 67 59 32 50 16 35 44 4 2 25 0 49 4 85 68 57 43 78 96 36 93 23 9 24 47 92 55 54 56...
output:
1
result:
ok single line: '1'
Test #46:
score: 49
Accepted
time: 22ms
memory: 11236kb
input:
200000 2 0 0 0 0 3 4 1 0 0 9 7 7 1 11 3 9 4 12 18 7 14 13 22 9 18 0 6 15 17 19 8 31 5 30 1 23 1 10 38 33 32 2 27 38 8 21 29 33 8 27 28 15 9 1 29 25 32 45 55 26 15 50 17 38 3 22 38 7 64 39 10 67 37 8 44 15 45 40 53 11 16 44 9 51 30 44 8 35 85 42 53 58 36 67 25 78 75 9 42 52 54 50 101 97 10 25 26 62 7...
output:
119331
result:
ok single line: '119331'
Test #47:
score: 49
Accepted
time: 24ms
memory: 11232kb
input:
200000 40 0 1 2 2 0 2 0 1 2 3 2 9 11 3 11 15 14 12 16 8 11 6 0 19 11 16 14 8 21 18 12 3 14 31 23 19 9 19 13 23 32 29 42 16 27 7 26 7 37 38 44 33 8 33 54 43 34 3 16 16 13 14 11 38 46 19 66 30 19 31 33 71 41 41 32 42 8 74 4 79 79 34 35 52 74 68 11 4 1 4 5 42 28 24 1 11 93 4 0 68 61 51 35 83 5 14 102 5...
output:
14
result:
ok single line: '14'
Test #48:
score: 49
Accepted
time: 23ms
memory: 11236kb
input:
200000 80 0 1 0 0 0 2 6 5 6 3 9 4 7 8 14 2 0 17 2 16 2 4 13 8 23 8 3 11 24 27 21 18 6 26 14 27 2 25 13 39 8 1 36 15 25 19 21 14 30 17 46 32 45 19 1 25 30 24 50 48 52 38 51 56 26 3 8 58 17 68 48 61 54 6 28 48 41 51 14 33 34 25 30 35 20 68 26 30 4 86 87 26 8 80 62 85 54 81 48 59 45 11 77 82 5 28 78 84...
output:
1
result:
ok single line: '1'
Test #49:
score: 49
Accepted
time: 25ms
memory: 11236kb
input:
200000 200 0 1 1 3 2 0 4 6 6 5 6 5 6 6 11 6 9 3 13 5 17 5 4 21 5 2 7 0 3 10 27 21 10 24 33 25 19 13 25 17 0 5 31 10 23 43 34 18 25 44 42 39 28 4 23 7 10 17 23 0 42 48 18 35 22 5 44 53 35 16 40 71 38 72 74 68 57 19 33 51 72 45 26 27 72 11 29 42 36 48 50 49 35 83 66 26 58 65 55 25 49 62 6 89 36 97 61 ...
output:
1
result:
ok single line: '1'
Test #50:
score: 49
Accepted
time: 4ms
memory: 6244kb
input:
100000 3 0 1 1 0 0 0 1 0 5 4 6 3 3 4 11 5 10 15 16 4 5 16 18 20 11 15 8 25 5 14 21 2 4 30 2 20 27 22 23 31 7 8 24 27 32 8 31 5 35 7 32 1 4 40 9 28 47 11 5 56 36 1 43 32 63 55 33 30 60 35 55 40 23 14 30 18 2 34 36 23 65 20 31 82 47 63 54 52 6 62 84 28 6 56 11 21 17 16 61 47 27 51 27 34 14 37 42 89 14...
output:
1000
result:
ok single line: '1000'
Test #51:
score: 49
Accepted
time: 5ms
memory: 6244kb
input:
100000 10 0 1 2 1 2 1 4 4 8 7 3 9 8 9 4 3 16 3 0 9 7 12 14 23 8 15 20 20 7 27 22 28 2 17 25 34 28 26 3 0 39 39 5 34 34 31 26 45 45 43 1 9 51 44 20 46 30 19 40 51 3 6 49 62 49 46 51 61 22 41 20 40 71 27 17 69 51 5 6 72 79 22 41 76 13 14 35 40 41 78 71 51 91 54 24 82 2 61 44 16 96 25 47 62 99 72 52 85...
output:
79
result:
ok single line: '79'
Test #52:
score: 49
Accepted
time: 4ms
memory: 6240kb
input:
100000 15 0 0 0 0 1 1 6 1 1 3 9 6 0 9 10 1 14 1 4 8 13 3 17 3 2 2 12 15 28 0 21 4 11 14 16 6 23 12 16 1 10 8 22 7 43 15 38 40 33 35 31 0 37 41 3 55 13 20 31 27 18 40 17 49 61 35 64 35 0 14 19 16 29 44 15 5 29 20 9 13 0 46 27 46 69 22 80 56 7 20 80 82 35 85 16 66 70 45 21 68 14 16 20 95 92 23 46 90 9...
output:
23
result:
ok single line: '23'
Test #53:
score: 49
Accepted
time: 10ms
memory: 9060kb
input:
200000 4 0 0 2 0 1 5 5 5 6 2 3 5 11 9 2 0 2 8 4 11 5 6 12 8 15 11 11 1 2 6 7 29 12 4 1 17 24 23 14 2 29 16 9 20 42 4 40 47 38 37 23 10 0 28 9 55 51 45 56 32 31 31 12 39 43 35 47 16 44 7 51 34 30 7 10 1 59 65 59 34 32 7 74 82 60 43 25 80 10 73 41 59 81 34 81 80 62 92 51 84 70 97 81 94 53 30 36 3 27 4...
output:
600
result:
ok single line: '600'
Test #54:
score: 49
Accepted
time: 9ms
memory: 9188kb
input:
200000 12 0 1 0 2 1 3 5 1 4 1 4 5 3 9 2 7 15 13 14 3 19 21 2 11 12 1 3 4 15 27 0 28 10 25 30 13 21 28 26 17 0 17 35 10 17 37 14 15 39 24 33 36 32 27 31 1 45 0 0 6 21 3 3 19 37 18 41 48 8 6 40 66 29 8 72 47 21 46 1 38 14 46 64 57 5 44 48 86 56 42 83 51 89 25 15 65 83 66 98 85 40 56 26 74 101 38 69 52...
output:
48
result:
ok single line: '48'
Test #55:
score: 49
Accepted
time: 8ms
memory: 9188kb
input:
200000 17 0 1 1 0 1 5 5 1 7 9 0 4 6 3 6 6 7 12 10 0 7 19 3 9 3 18 9 16 16 1 5 21 14 21 9 2 24 18 11 20 37 5 34 13 10 3 11 31 13 37 32 26 22 14 51 8 56 35 46 58 57 28 26 26 18 65 37 62 16 45 38 10 18 28 0 21 59 25 18 25 42 7 23 17 63 16 60 45 77 57 81 54 31 28 89 78 91 77 21 89 42 36 38 7 94 70 4 34 ...
output:
12
result:
ok single line: '12'
Test #56:
score: 49
Accepted
time: 1ms
memory: 3840kb
input:
2400 4 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
435
result:
ok single line: '435'
Test #57:
score: 49
Accepted
time: 3ms
memory: 5376kb
input:
21200 2000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...
output:
11
result:
ok single line: '11'
Test #58:
score: 49
Accepted
time: 7ms
memory: 12476kb
input:
100000 10000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...
output:
9
result:
ok single line: '9'
Test #59:
score: 49
Accepted
time: 24ms
memory: 15588kb
input:
199999 10000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...
output:
11
result:
ok single line: '11'
Test #60:
score: 49
Accepted
time: 13ms
memory: 12132kb
input:
195001 7 0 1 2 3 0 5 6 7 0 9 10 11 0 13 14 15 0 17 18 19 0 21 22 23 0 25 26 27 0 29 30 31 0 33 34 35 0 37 38 39 0 41 42 43 0 45 46 47 0 49 50 51 0 53 54 55 0 57 58 59 0 61 62 63 0 65 66 67 0 69 70 71 0 73 74 75 0 77 78 79 0 81 82 83 0 85 86 87 0 89 90 91 0 93 94 95 0 97 98 99 0 101 102 103 0 105 106...
output:
40021
result:
ok single line: '40021'
Test #61:
score: 49
Accepted
time: 19ms
memory: 11624kb
input:
190001 200 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...
output:
1000
result:
ok single line: '1000'