QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104830 | #6307. Chase Game 2 | maspy | AC ✓ | 42ms | 11708kb | C++20 | 20.1kb | 2023-05-12 02:13:36 | 2023-05-12 02:13:38 |
Judging History
answer
#line 1 "library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'000'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name( \
a, vector<vector<vector<type>>>( \
b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) \
for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T, typename U>
T ceil(T x, U y) {
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U>
T floor(T x, U y) {
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sum = 0;
for (auto &&a: A) sum += a;
return sum;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
assert(!que.empty());
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
assert(!que.empty());
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids),
[&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
#endif
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>
namespace fastio {
#define FASTIO
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
template <class T>
static auto check(T &&x) -> decltype(x.write(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};
struct has_read_impl {
template <class T>
static auto check(T &&x) -> decltype(x.read(), std::true_type{});
template <class T>
static auto check(...) -> std::false_type;
};
template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};
struct Scanner {
FILE *fp;
char line[(1 << 15) + 1];
size_t st = 0, ed = 0;
void reread() {
memmove(line, line + st, ed - st);
ed -= st;
st = 0;
ed += fread(line + ed, 1, (1 << 15) - ed, fp);
line[ed] = '\0';
}
bool succ() {
while (true) {
if (st == ed) {
reread();
if (st == ed) return false;
}
while (st != ed && isspace(line[st])) st++;
if (st != ed) break;
}
if (ed - st <= 50) {
bool sep = false;
for (size_t i = st; i < ed; i++) {
if (isspace(line[i])) {
sep = true;
break;
}
}
if (!sep) reread();
}
return true;
}
template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
while (true) {
size_t sz = 0;
while (st + sz < ed && !isspace(line[st + sz])) sz++;
ref.append(line + st, sz);
st += sz;
if (!sz || st != ed) break;
reread();
}
return true;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
bool read_single(T &ref) {
if (!succ()) return false;
bool neg = false;
if (line[st] == '-') {
neg = true;
st++;
}
ref = T(0);
while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
if (neg) ref = -ref;
return true;
}
template <typename T,
typename enable_if<has_read<T>::value>::type * = nullptr>
inline bool read_single(T &x) {
x.read();
return true;
}
bool read_single(double &ref) {
string s;
if (!read_single(s)) return false;
ref = std::stod(s);
return true;
}
bool read_single(char &ref) {
string s;
if (!read_single(s) || s.size() != 1) return false;
ref = s[0];
return true;
}
template <class T>
bool read_single(vector<T> &ref) {
for (auto &d: ref) {
if (!read_single(d)) return false;
}
return true;
}
template <class T, class U>
bool read_single(pair<T, U> &p) {
return (read_single(p.first) && read_single(p.second));
}
template <size_t N = 0, typename T>
void read_single_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
read_single(x);
read_single_tuple<N + 1>(t);
}
}
template <class... T>
bool read_single(tuple<T...> &tpl) {
read_single_tuple(tpl);
return true;
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
bool f = read_single(h);
assert(f);
read(t...);
}
Scanner(FILE *fp) : fp(fp) {}
};
struct Printer {
Printer(FILE *_fp) : fp(_fp) {}
~Printer() { flush(); }
static constexpr size_t SIZE = 1 << 15;
FILE *fp;
char line[SIZE], small[50];
size_t pos = 0;
void flush() {
fwrite(line, 1, pos, fp);
pos = 0;
}
void write(const char val) {
if (pos == SIZE) flush();
line[pos++] = val;
}
template <class T, enable_if_t<is_integral<T>::value, int> = 0>
void write(T val) {
if (pos > (1 << 15) - 50) flush();
if (val == 0) {
write('0');
return;
}
if (val < 0) {
write('-');
val = -val; // todo min
}
size_t len = 0;
while (val) {
small[len++] = char(0x30 | (val % 10));
val /= 10;
}
for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
pos += len;
}
void write(const string s) {
for (char c: s) write(c);
}
void write(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) write(s[i]);
}
void write(const double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
void write(const long double x) {
ostringstream oss;
oss << fixed << setprecision(15) << x;
string s = oss.str();
write(s);
}
template <typename T,
typename enable_if<has_write<T>::value>::type * = nullptr>
inline void write(T x) {
x.write();
}
template <class T>
void write(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
template <class T, class U>
void write(const pair<T, U> val) {
write(val.first);
write(' ');
write(val.second);
}
template <size_t N = 0, typename T>
void write_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { write(' '); }
const auto x = std::get<N>(t);
write(x);
write_tuple<N + 1>(t);
}
}
template <class... T>
bool write(tuple<T...> tpl) {
write_tuple(tpl);
return true;
}
template <class T, size_t S>
void write(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) write(' ');
write(val[i]);
}
}
void write(i128 val) {
string s;
bool negative = 0;
if (val < 0) {
negative = 1;
val = -val;
}
while (val) {
s += '0' + int(val % 10);
val /= 10;
}
if (negative) s += "-";
reverse(all(s));
if (len(s) == 0) s = "0";
write(s);
}
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
printer.write(head);
if (sizeof...(Tail)) printer.write(' ');
print(forward<Tail>(tail)...);
}
void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
scanner.read(head);
read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 2 "library/graph/base.hpp"
template <typename T>
struct Edge {
int frm, to;
T cost;
int id;
};
template <typename T = int, bool directed = false>
struct Graph {
int N, M;
using cost_type = T;
using edge_type = Edge<T>;
vector<edge_type> edges;
vector<int> indptr;
vector<edge_type> csr_edges;
vc<int> vc_deg, vc_indeg, vc_outdeg;
bool prepared;
class OutgoingEdges {
public:
OutgoingEdges(const Graph* G, int l, int r) : G(G), l(l), r(r) {}
const edge_type* begin() const {
if (l == r) { return 0; }
return &G->csr_edges[l];
}
const edge_type* end() const {
if (l == r) { return 0; }
return &G->csr_edges[r];
}
private:
const Graph* G;
int l, r;
};
bool is_prepared() { return prepared; }
constexpr bool is_directed() { return directed; }
Graph() : N(0), M(0), prepared(0) {}
Graph(int N) : N(N), M(0), prepared(0) {}
void build(int n) {
N = n, M = 0;
prepared = 0;
edges.clear();
indptr.clear();
csr_edges.clear();
vc_deg.clear();
vc_indeg.clear();
vc_outdeg.clear();
}
void add(int frm, int to, T cost = 1, int i = -1) {
assert(!prepared);
assert(0 <= frm && 0 <= to && to < N);
if (i == -1) i = M;
auto e = edge_type({frm, to, cost, i});
edges.eb(e);
++M;
}
// wt, off
void read_tree(bool wt = false, int off = 1) { read_graph(N - 1, wt, off); }
void read_graph(int M, bool wt = false, int off = 1) {
for (int m = 0; m < M; ++m) {
INT(a, b);
a -= off, b -= off;
if (!wt) {
add(a, b);
} else {
T c;
read(c);
add(a, b, c);
}
}
build();
}
void read_parent(int off = 1) {
for (int v = 1; v < N; ++v) {
INT(p);
p -= off;
add(p, v);
}
build();
}
void build() {
assert(!prepared);
prepared = true;
indptr.assign(N + 1, 0);
for (auto&& e: edges) {
indptr[e.frm + 1]++;
if (!directed) indptr[e.to + 1]++;
}
for (int v = 0; v < N; ++v) { indptr[v + 1] += indptr[v]; }
auto counter = indptr;
csr_edges.resize(indptr.back() + 1);
for (auto&& e: edges) {
csr_edges[counter[e.frm]++] = e;
if (!directed)
csr_edges[counter[e.to]++] = edge_type({e.to, e.frm, e.cost, e.id});
}
}
OutgoingEdges operator[](int v) const {
assert(prepared);
return {this, indptr[v], indptr[v + 1]};
}
vc<int> deg_array() {
if (vc_deg.empty()) calc_deg();
return vc_deg;
}
pair<vc<int>, vc<int>> deg_array_inout() {
if (vc_indeg.empty()) calc_deg_inout();
return {vc_indeg, vc_outdeg};
}
int deg(int v) {
if (vc_deg.empty()) calc_deg();
return vc_deg[v];
}
int in_deg(int v) {
if (vc_indeg.empty()) calc_deg_inout();
return vc_indeg[v];
}
int out_deg(int v) {
if (vc_outdeg.empty()) calc_deg_inout();
return vc_outdeg[v];
}
void debug() {
print("Graph");
if (!prepared) {
print("frm to cost id");
for (auto&& e: edges) print(e.frm, e.to, e.cost, e.id);
} else {
print("indptr", indptr);
print("frm to cost id");
FOR(v, N) for (auto&& e: (*this)[v]) print(e.frm, e.to, e.cost, e.id);
}
}
// G における頂点 V[i] が、新しいグラフで i になるようにする
Graph<T, directed> rearrange(vc<int> V) {
int n = len(V);
map<int, int> MP;
FOR(i, n) MP[V[i]] = i;
Graph<T, directed> G(n);
for (auto&& e: edges) {
if (MP.count(e.frm) && MP.count(e.to)) {
G.add(MP[e.frm], MP[e.to], e.cost);
}
}
G.build();
return G;
}
private:
void calc_deg() {
assert(vc_deg.empty());
vc_deg.resize(N);
for (auto&& e: edges) vc_deg[e.frm]++, vc_deg[e.to]++;
}
void calc_deg_inout() {
assert(vc_indeg.empty());
vc_indeg.resize(N);
vc_outdeg.resize(N);
for (auto&& e: edges) { vc_indeg[e.to]++, vc_outdeg[e.frm]++; }
}
};
#line 3 "library/graph/shortest_path/bfs01.hpp"
template <typename T, typename GT>
pair<vc<T>, vc<int>> bfs01(GT& G, int v) {
assert(G.is_prepared());
int N = G.N;
vc<T> dist(N, infty<T>);
vc<int> par(N, -1);
deque<int> que;
dist[v] = 0;
que.push_front(v);
while (!que.empty()) {
auto v = que.front();
que.pop_front();
for (auto&& e: G[v]) {
if (dist[e.to] == infty<T> || dist[e.to] > dist[e.frm] + e.cost) {
dist[e.to] = dist[e.frm] + e.cost;
par[e.to] = e.frm;
if (e.cost == 0)
que.push_front(e.to);
else
que.push_back(e.to);
}
}
}
return {dist, par};
}
// 多点スタート。[dist, par, root]
template <typename T, typename GT>
tuple<vc<T>, vc<int>, vc<int>> bfs01(GT& G, vc<int> vs) {
assert(G.is_prepared());
int N = G.N;
vc<T> dist(N, infty<T>);
vc<int> par(N, -1);
vc<int> root(N, -1);
deque<int> que;
for (auto&& v: vs) {
dist[v] = 0;
root[v] = v;
que.push_front(v);
}
while (!que.empty()) {
auto v = que.front();
que.pop_front();
for (auto&& e: G[v]) {
if (dist[e.to] == infty<T> || dist[e.to] > dist[e.frm] + e.cost) {
dist[e.to] = dist[e.frm] + e.cost;
root[e.to] = root[e.frm];
par[e.to] = e.frm;
if (e.cost == 0)
que.push_front(e.to);
else
que.push_back(e.to);
}
}
}
return {dist, par, root};
}
#line 1 "library/graph/shortest_path/restore_path.hpp"
vector<int> restore_path(vector<int> par, int t){
vector<int> pth = {t};
while (par[pth.back()] != -1) pth.eb(par[pth.back()]);
reverse(all(pth));
return pth;
}
#line 3 "library/graph/tree_diameter.hpp"
template <typename T, typename GT>
pair<T, vc<int>> tree_diameter(GT& G) {
assert(G.is_prepared());
T sm = 0;
for (auto&& e: G.edges) {
sm += e.cost;
assert(sm < infty<T>);
}
int A, B;
auto [distA, parA] = bfs01<T>(G, 0);
A = max_element(all(distA)) - distA.begin();
auto [dist, par] = bfs01<T>(G, A);
B = max_element(all(dist)) - dist.begin();
vc<int> P = restore_path(par, B);
return {dist[B], P};
}
#line 5 "main.cpp"
void solve() {
LL(N);
Graph<int, 0> G(N);
G.read_tree();
int d = tree_diameter<int>(G).fi;
if (d <= 2) return print(-1);
auto deg = G.deg_array();
vc<int> A;
FOR(v, N) if (deg[v] == 1) {
for (auto&& e: G[v]) A.eb(e.to);
}
ll n = len(A);
map<int, int> MP;
for (auto&& x: A) MP[x]++;
ll ANS = ceil(n, 2);
for (auto&& [a, b]: MP) chmax(ANS, b);
print(ANS);
}
signed main() {
INT(T);
FOR(T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3520kb
input:
4 2 1 2 4 1 2 2 3 3 4 4 1 2 2 3 2 4 5 1 2 2 3 3 4 3 5
output:
-1 1 -1 2
result:
ok 4 number(s): "-1 1 -1 2"
Test #2:
score: 0
Accepted
time: 11ms
memory: 3556kb
input:
10000 4 1 2 1 3 3 4 4 1 2 1 3 1 4 4 1 2 2 3 1 4 5 1 2 2 3 1 4 4 5 5 1 2 2 3 3 4 4 5 4 1 2 2 3 2 4 5 1 2 1 3 2 4 2 5 4 1 2 2 3 1 4 5 1 2 1 3 2 4 1 5 5 1 2 2 3 3 4 2 5 5 1 2 1 3 2 4 2 5 4 1 2 1 3 3 4 5 1 2 1 3 3 4 1 5 4 1 2 1 3 1 4 5 1 2 1 3 3 4 3 5 5 1 2 2 3 3 4 3 5 4 1 2 1 3 2 4 5 1 2 2 3 2 4 3 5 5 ...
output:
1 -1 1 1 1 -1 2 1 2 2 2 1 2 -1 2 2 1 2 2 1 1 1 -1 2 2 2 1 -1 1 1 2 1 1 -1 1 2 1 1 1 -1 1 1 2 2 2 1 1 1 -1 1 2 1 1 2 1 2 1 1 2 -1 -1 -1 2 2 2 1 1 1 2 2 2 -1 1 2 -1 1 1 -1 2 -1 -1 1 2 2 2 1 1 1 1 1 1 1 1 1 2 -1 1 1 2 -1 2 1 1 1 -1 2 -1 1 -1 -1 2 -1 2 1 2 2 1 1 1 1 2 1 1 1 1 -1 2 1 2 1 1 1 1 1 1 1 2 -1...
result:
ok 10000 numbers
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2 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 4 2 2 3 2 2 3 4 3 4 3 3 3 3 3 3 3 2 3 3 2 2 3 4 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 2 3 2 2 3 3 2 3 3 2 2 3 2 3 2 3 3 2 2 3 3 2 3 3 3 2 3 3 2 2 3 3 3 2 3 3 5 4 3 2 3 2 3 3 3 3 2 2 3 3 3 3 3 3 2 3 2 3 3 3 4 3 2 3 2 3 3 3 2 ...
result:
ok 10000 numbers
Test #5:
score: 0
Accepted
time: 25ms
memory: 3572kb
input:
10000 20 1 2 1 3 1 4 2 5 4 6 6 7 2 8 4 9 7 10 6 11 4 12 6 13 13 14 10 15 8 16 11 17 5 18 15 19 10 20 19 1 2 1 3 2 4 3 5 4 6 1 7 1 8 2 9 4 10 10 11 8 12 2 13 4 14 1 15 4 16 4 17 14 18 3 19 20 1 2 1 3 1 4 1 5 1 6 5 7 3 8 5 9 1 10 8 11 8 12 2 13 7 14 4 15 2 16 12 17 14 18 18 19 1 20 19 1 2 1 3 3 4 2 5 ...
output:
5 6 5 5 5 4 5 6 3 6 5 4 5 6 5 6 5 5 5 5 5 4 5 5 5 6 6 5 6 4 5 5 6 4 5 5 4 5 3 6 5 5 6 5 5 4 5 3 6 6 5 5 6 4 6 5 5 5 6 5 5 5 4 6 4 5 5 5 4 5 5 5 6 7 5 5 6 6 4 6 5 5 5 5 6 6 5 6 6 6 4 5 6 4 5 4 4 5 5 6 5 5 5 7 5 5 5 5 4 4 6 4 6 4 5 4 4 6 4 5 5 5 4 5 5 5 6 5 5 6 5 5 3 4 6 4 4 5 5 5 4 4 6 5 5 5 5 6 5 6 ...
result:
ok 10000 numbers
Test #6:
score: 0
Accepted
time: 22ms
memory: 3568kb
input:
4000 45 1 2 2 3 2 4 4 5 2 6 2 7 7 8 8 9 1 10 1 11 3 12 11 13 8 14 13 15 8 16 16 17 12 18 11 19 6 20 3 21 6 22 15 23 13 24 2 25 22 26 8 27 20 28 1 29 22 30 9 31 12 32 7 33 31 34 31 35 25 36 19 37 34 38 4 39 14 40 40 41 3 42 42 43 26 44 21 45 46 1 2 2 3 2 4 3 5 4 6 2 7 6 8 1 9 1 10 9 11 4 12 8 13 6 14...
output:
11 11 12 14 10 11 14 11 14 12 11 12 12 11 13 12 12 13 12 13 10 10 13 12 11 11 12 11 12 12 11 12 13 10 14 12 11 9 11 12 12 11 13 12 14 13 10 9 12 13 12 12 12 14 12 11 13 11 13 13 14 11 13 13 13 11 11 13 11 13 13 11 11 12 12 11 11 11 13 12 13 11 13 12 12 13 13 12 13 14 11 12 11 12 11 12 12 13 14 12 12...
result:
ok 4000 numbers
Test #7:
score: 0
Accepted
time: 23ms
memory: 3512kb
input:
2000 94 1 2 2 3 3 4 4 5 1 6 3 7 5 8 4 9 3 10 7 11 8 12 12 13 4 14 12 15 12 16 5 17 13 18 6 19 16 20 14 21 17 22 7 23 10 24 1 25 22 26 18 27 23 28 19 29 17 30 13 31 11 32 8 33 3 34 21 35 23 36 35 37 28 38 6 39 15 40 28 41 26 42 36 43 1 44 37 45 1 46 30 47 7 48 37 49 3 50 23 51 47 52 33 53 1 54 34 55 ...
output:
25 23 22 23 25 23 24 25 21 21 24 24 23 21 25 25 25 23 25 24 23 22 26 26 23 24 25 26 24 23 22 25 25 24 23 22 24 22 24 23 24 26 25 22 22 22 25 21 25 24 26 26 25 24 25 24 24 25 23 24 23 24 21 23 24 25 22 25 24 25 22 25 22 23 24 26 25 27 23 24 25 25 23 23 24 23 23 25 25 27 22 21 23 28 27 23 25 26 23 23 ...
result:
ok 2000 numbers
Test #8:
score: 0
Accepted
time: 27ms
memory: 3564kb
input:
200 959 1 2 1 3 2 4 2 5 3 6 1 7 5 8 7 9 1 10 2 11 2 12 6 13 9 14 14 15 3 16 6 17 12 18 5 19 7 20 12 21 18 22 1 23 8 24 11 25 2 26 19 27 4 28 21 29 15 30 22 31 21 32 32 33 15 34 22 35 11 36 22 37 34 38 18 39 7 40 13 41 29 42 40 43 34 44 28 45 37 46 10 47 8 48 12 49 2 50 17 51 39 52 35 53 16 54 31 55 ...
output:
236 231 238 231 227 235 241 230 238 230 236 237 224 237 241 235 244 242 245 243 234 236 239 231 228 227 228 238 243 234 238 255 253 230 239 254 226 233 230 242 235 240 235 242 229 249 246 249 242 243 234 237 235 227 249 240 244 233 234 244 241 233 234 225 237 242 239 242 232 248 233 234 220 222 227 ...
result:
ok 200 numbers
Test #9:
score: 0
Accepted
time: 26ms
memory: 4124kb
input:
20 9597 1 2 1 3 1 4 4 5 3 6 2 7 2 8 2 9 5 10 7 11 2 12 9 13 2 14 1 15 5 16 11 17 16 18 2 19 11 20 9 21 12 22 16 23 10 24 21 25 12 26 9 27 6 28 1 29 13 30 15 31 18 32 6 33 26 34 21 35 16 36 19 37 30 38 36 39 30 40 27 41 14 42 40 43 32 44 2 45 34 46 4 47 26 48 32 49 24 50 17 51 27 52 36 53 44 54 7 55 ...
output:
2403 2490 2391 2263 2356 2482 2384 2469 2386 2265 2283 2342 2381 2382 2261 2353 2287 2499 2458 2426
result:
ok 20 numbers
Test #10:
score: 0
Accepted
time: 42ms
memory: 11580kb
input:
2 92316 1 2 2 3 1 4 3 5 2 6 1 7 6 8 8 9 4 10 5 11 4 12 8 13 5 14 7 15 14 16 15 17 4 18 12 19 3 20 1 21 4 22 8 23 16 24 20 25 15 26 15 27 7 28 7 29 15 30 27 31 18 32 14 33 28 34 22 35 11 36 16 37 30 38 30 39 5 40 32 41 16 42 12 43 26 44 16 45 38 46 34 47 35 48 41 49 22 50 18 51 7 52 5 53 1 54 37 55 1...
output:
22980 24011
result:
ok 2 number(s): "22980 24011"
Test #11:
score: 0
Accepted
time: 17ms
memory: 3604kb
input:
10000 9 9 2 5 7 8 9 9 4 3 5 3 6 9 5 1 9 9 4 2 9 4 4 8 1 4 9 7 4 6 5 3 5 4 9 4 1 9 6 7 4 4 2 7 5 2 3 6 2 3 8 9 7 9 6 8 5 2 9 4 1 3 6 5 4 6 6 3 9 6 3 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 2 4 -1 -1 3 4 6 6 7 4 -1 4 4 2 -1 4 5 4 2 4 4 -1 2 3 3 3 5 6 3 6 5 -1 ...
result:
ok 10000 numbers
Test #13:
score: 0
Accepted
time: 23ms
memory: 3480kb
input:
10000 19 2 13 12 2 3 2 2 4 11 2 14 2 5 2 2 15 18 2 10 2 2 1 2 19 9 2 2 7 2 17 6 2 8 2 16 2 19 8 1 15 1 1 2 1 6 11 1 3 1 18 1 14 1 1 7 1 12 17 1 1 19 1 13 1 10 5 1 16 1 9 1 1 4 19 17 16 6 17 1 17 3 6 17 8 6 9 17 14 19 17 7 17 17 11 6 12 2 6 17 18 4 17 13 17 17 5 17 10 17 15 19 17 2 17 19 3 17 11 17 1...
output:
-1 -1 13 -1 8 -1 5 12 6 9 5 6 -1 -1 -1 5 5 -1 10 -1 10 7 6 -1 -1 7 5 -1 4 11 -1 9 -1 10 9 -1 6 8 10 10 -1 -1 9 5 12 5 11 12 6 7 5 6 6 -1 6 9 5 6 9 -1 10 8 -1 -1 9 5 10 -1 12 10 10 -1 -1 10 -1 5 6 -1 5 5 5 4 -1 5 10 6 7 9 8 9 4 5 4 7 10 -1 -1 6 -1 6 9 -1 -1 6 10 -1 6 7 4 5 -1 -1 -1 -1 12 6 6 7 5 -1 1...
result:
ok 10000 numbers
Test #14:
score: 0
Accepted
time: 24ms
memory: 3552kb
input:
10000 18 18 10 5 10 10 9 18 15 2 18 10 16 10 8 4 18 17 10 3 10 18 12 14 10 1 18 13 18 7 18 6 18 11 10 19 13 10 4 13 11 4 5 7 4 9 2 5 13 14 3 13 17 7 13 17 12 1 16 19 4 12 18 6 8 13 6 3 3 15 14 16 20 9 5 18 4 8 4 2 16 12 2 12 19 13 10 4 15 14 4 1 4 4 20 4 2 13 4 4 5 4 17 7 20 11 4 6 14 3 17 18 1 8 10...
output:
8 5 6 8 5 -1 -1 6 10 -1 -1 6 4 4 14 6 5 6 5 10 -1 6 9 11 8 8 9 -1 12 12 4 5 5 5 -1 11 7 -1 -1 8 9 9 9 7 5 8 -1 5 5 7 5 5 8 5 12 6 7 9 10 -1 5 -1 5 11 6 5 12 7 -1 5 9 10 -1 10 6 4 8 10 10 -1 4 5 6 12 -1 7 6 7 6 5 4 5 7 5 10 5 4 6 7 7 7 -1 -1 5 -1 9 5 10 10 8 -1 5 -1 6 -1 9 -1 11 5 8 11 8 12 11 10 11 ...
result:
ok 10000 numbers
Test #15:
score: 0
Accepted
time: 23ms
memory: 3464kb
input:
4000 48 16 37 27 40 41 37 37 11 28 27 27 29 27 33 39 37 44 37 37 22 19 37 27 17 27 7 4 27 37 45 27 3 46 37 37 15 37 36 43 37 27 37 37 34 25 27 37 2 27 10 37 35 27 26 37 18 42 27 27 9 27 24 27 23 47 37 27 13 48 37 20 27 30 27 27 14 27 31 37 6 8 37 27 21 38 37 37 1 12 27 27 32 37 5 46 13 17 45 32 40 2...
output:
23 12 10 24 18 24 18 -1 11 12 15 15 29 12 -1 13 20 -1 15 12 -1 11 11 24 19 16 29 27 26 -1 -1 12 22 15 16 26 25 12 24 26 13 29 15 -1 -1 -1 23 12 26 13 -1 14 -1 21 21 25 -1 -1 13 13 -1 12 14 13 12 13 13 14 15 -1 16 21 14 26 23 13 16 12 23 14 17 17 24 29 17 14 19 23 29 -1 12 -1 12 19 14 24 15 19 15 15 ...
result:
ok 4000 numbers
Test #16:
score: 0
Accepted
time: 19ms
memory: 3516kb
input:
4000 46 8 28 14 4 4 6 41 4 3 4 36 22 4 30 28 18 44 29 34 32 18 45 4 32 4 46 4 31 44 28 43 4 42 21 17 4 37 4 4 23 26 11 21 14 7 4 4 2 16 4 40 18 4 38 4 27 15 4 9 4 5 4 4 12 4 24 4 20 19 4 25 14 29 39 38 33 11 4 43 13 35 10 36 28 46 1 44 35 4 22 47 25 44 29 23 13 26 45 10 10 23 22 44 32 44 7 42 25 12 ...
output:
19 18 24 28 18 -1 14 12 -1 -1 25 25 17 13 11 22 11 -1 28 16 13 12 -1 29 13 11 29 -1 18 -1 11 -1 23 12 12 13 20 13 18 12 24 20 23 23 17 26 -1 23 26 15 26 21 12 -1 24 24 30 -1 -1 -1 18 21 11 13 -1 -1 16 15 25 -1 25 20 10 25 27 -1 15 19 14 30 19 23 31 15 27 24 13 15 -1 23 20 -1 -1 19 -1 12 11 19 -1 11 ...
result:
ok 4000 numbers
Test #17:
score: 0
Accepted
time: 22ms
memory: 3504kb
input:
2000 98 96 39 67 96 76 1 76 75 82 76 65 76 76 13 76 60 2 66 53 76 76 90 76 45 62 84 51 76 6 74 21 33 68 23 81 6 72 17 76 14 26 41 24 95 81 48 79 76 11 76 30 76 76 64 55 76 44 76 3 15 77 32 88 68 57 12 76 63 59 76 7 81 76 10 76 87 40 92 76 28 57 67 17 67 76 70 9 68 20 69 17 5 65 38 36 89 23 94 71 25 ...
output:
32 50 51 34 50 50 54 49 31 24 -1 58 47 36 -1 52 47 54 32 36 47 50 22 34 -1 52 32 53 34 -1 25 23 -1 26 26 30 25 21 45 47 -1 22 51 41 34 -1 -1 44 32 31 53 54 51 26 48 -1 -1 -1 24 26 33 23 23 -1 48 34 53 22 49 30 48 26 -1 -1 31 24 52 -1 33 48 43 39 37 -1 54 -1 53 27 25 32 58 62 24 -1 23 -1 23 26 32 -1 ...
result:
ok 2000 numbers
Test #18:
score: 0
Accepted
time: 22ms
memory: 3508kb
input:
2000 93 21 92 6 91 12 59 53 8 4 59 37 59 14 85 82 59 35 59 19 20 59 54 49 59 59 62 23 59 10 59 46 32 65 39 41 10 2 91 59 55 42 74 59 17 39 77 56 15 9 19 70 59 16 60 26 67 14 59 59 90 77 54 59 68 59 60 45 59 63 64 76 92 63 59 86 26 84 59 59 44 69 59 46 93 59 46 59 9 32 43 41 7 56 59 78 59 59 58 31 59...
output:
36 31 22 25 24 -1 58 26 22 37 31 59 -1 36 21 45 -1 -1 48 -1 23 54 -1 51 35 33 -1 22 33 23 55 53 37 49 25 33 39 42 36 40 55 44 -1 49 25 39 25 -1 33 -1 -1 -1 24 -1 45 51 27 -1 49 -1 49 -1 24 -1 24 -1 21 50 35 23 -1 24 34 41 52 31 -1 23 -1 29 58 32 26 52 33 51 32 31 -1 26 23 49 21 37 52 -1 24 26 -1 24 ...
result:
ok 2000 numbers
Test #19:
score: 0
Accepted
time: 16ms
memory: 3660kb
input:
200 948 17 489 79 914 669 852 634 946 442 360 722 329 66 632 869 397 56 96 309 83 133 17 86 578 67 535 808 825 163 810 367 350 351 853 137 325 349 338 67 399 273 307 148 871 548 428 571 817 940 22 494 886 422 277 545 34 650 88 942 464 201 867 917 705 775 67 132 867 447 80 230 198 105 76 742 796 884 ...
output:
238 228 311 335 -1 228 -1 305 220 498 317 -1 -1 229 -1 -1 -1 226 308 245 313 -1 -1 243 -1 478 -1 327 332 492 482 477 484 512 463 482 317 -1 340 -1 469 -1 506 246 469 -1 329 -1 461 252 232 461 328 -1 299 223 244 321 259 495 473 -1 499 507 497 246 250 473 341 240 489 329 497 301 -1 304 -1 308 306 318 ...
result:
ok 200 numbers
Test #20:
score: 0
Accepted
time: 21ms
memory: 3616kb
input:
200 994 228 352 219 305 893 377 538 253 563 847 836 856 900 721 9 92 823 335 197 796 641 673 580 747 333 415 382 721 857 480 839 442 370 85 300 805 622 446 712 851 861 329 557 887 530 865 132 928 591 59 531 736 185 749 23 209 488 344 55 384 738 121 898 908 656 788 318 832 231 703 904 538 766 827 303...
output:
247 -1 324 -1 236 472 -1 496 332 473 508 306 326 325 -1 242 300 495 -1 -1 -1 346 -1 499 328 -1 481 455 322 -1 478 325 472 242 -1 -1 476 -1 335 313 477 298 -1 331 233 -1 327 242 -1 231 -1 478 -1 488 240 495 -1 311 465 332 499 248 -1 472 -1 468 334 -1 505 -1 510 323 479 -1 -1 473 236 320 238 237 227 4...
result:
ok 200 numbers
Test #21:
score: 0
Accepted
time: 22ms
memory: 4120kb
input:
20 9437 1041 614 2260 1041 1041 6652 1041 1062 5344 1041 1041 7452 7610 1041 1041 5923 1041 5301 7923 1041 1041 4157 1041 2967 1041 1141 1041 2909 1041 8211 1041 8350 3111 1041 4586 1041 9059 1041 4166 1041 1041 5399 1041 7089 1041 7274 1041 9119 4262 1041 8772 1041 1337 1041 7182 1041 1041 7957 104...
output:
-1 2463 4553 2356 3027 -1 -1 3088 3138 4832 -1 -1 4962 -1 4975 4921 -1 2421 2447 2323
result:
ok 20 numbers
Test #22:
score: 0
Accepted
time: 19ms
memory: 4048kb
input:
20 9157 1840 2053 4000 2053 2053 3759 5162 2053 2053 5660 2053 3419 7930 2053 2053 5157 2882 2053 2053 3253 2558 2053 8765 2053 7636 2053 2053 8803 2053 736 2053 9032 2053 4816 2053 1955 2053 8119 6138 2053 2053 3020 1894 2053 2053 1232 2053 1282 2053 5570 1262 2053 2504 2053 5169 2053 4338 2053 205...
output:
-1 2298 3322 4685 4911 4755 4858 -1 4795 2279 4799 2378 2455 2421 4674 2331 -1 4955 3039 4624
result:
ok 20 numbers
Test #23:
score: 0
Accepted
time: 23ms
memory: 11376kb
input:
2 97074 85963 67826 85963 58732 85963 66509 18931 85963 24345 85963 55283 87512 35724 35295 52714 85963 77338 64660 86660 31150 90257 89313 85963 10008 40466 85963 59061 65531 40301 85963 36139 52308 33257 85963 85963 5002 12888 11473 5932 75469 85963 22794 67230 85963 39349 85963 14191 85963 1243 8...
output:
32327 46820
result:
ok 2 number(s): "32327 46820"
Test #24:
score: 0
Accepted
time: 31ms
memory: 11708kb
input:
2 94295 28534 2134 2310 28534 28534 87013 49342 90726 87228 28534 79091 28534 84629 20054 28534 65122 62137 18206 26136 29225 75846 28534 18413 73926 56246 28534 32682 28534 73339 28534 67264 88141 14488 29602 30585 11013 71473 28534 63066 57800 63481 2923 27807 73127 28534 87446 67889 28878 14097 4...
output:
31501 32940
result:
ok 2 number(s): "31501 32940"