QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#735268 | #9564. Hey, Have You Seen My Kangaroo? | maspy | AC ✓ | 561ms | 65700kb | C++23 | 32.4kb | 2024-11-11 18:51:26 | 2024-11-11 18:51:26 |
Judging History
answer
#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
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); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (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>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#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) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
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;
(check(x) ? ok : ng) = 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;
(check(x) ? ok : ng) = 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;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __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 3 "main.cpp"
#line 2 "/home/maspy/compro/library/graph/tree.hpp"
#line 2 "/home/maspy/compro/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 {
static constexpr bool is_directed = directed;
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; }
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;
}
#ifdef FASTIO
// 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();
}
#endif
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];
}
#ifdef FASTIO
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);
}
}
#endif
vc<int> new_idx;
vc<bool> used_e;
// G における頂点 V[i] が、新しいグラフで i になるようにする
// {G, es}
// sum(deg(v)) の計算量になっていて、
// 新しいグラフの n+m より大きい可能性があるので注意
Graph<T, directed> rearrange(vc<int> V, bool keep_eid = 0) {
if (len(new_idx) != N) new_idx.assign(N, -1);
int n = len(V);
FOR(i, n) new_idx[V[i]] = i;
Graph<T, directed> G(n);
vc<int> history;
FOR(i, n) {
for (auto&& e: (*this)[V[i]]) {
if (len(used_e) <= e.id) used_e.resize(e.id + 1);
if (used_e[e.id]) continue;
int a = e.frm, b = e.to;
if (new_idx[a] != -1 && new_idx[b] != -1) {
history.eb(e.id);
used_e[e.id] = 1;
int eid = (keep_eid ? e.id : -1);
G.add(new_idx[a], new_idx[b], e.cost, eid);
}
}
}
FOR(i, n) new_idx[V[i]] = -1;
for (auto&& eid: history) used_e[eid] = 0;
G.build();
return G;
}
Graph<T, true> to_directed_tree(int root = -1) {
if (root == -1) root = 0;
assert(!is_directed && prepared && M == N - 1);
Graph<T, true> G1(N);
vc<int> par(N, -1);
auto dfs = [&](auto& dfs, int v) -> void {
for (auto& e: (*this)[v]) {
if (e.to == par[v]) continue;
par[e.to] = v, dfs(dfs, e.to);
}
};
dfs(dfs, root);
for (auto& e: edges) {
int a = e.frm, b = e.to;
if (par[a] == b) swap(a, b);
assert(par[b] == a);
G1.add(a, b, e.cost);
}
G1.build();
return G1;
}
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 4 "/home/maspy/compro/library/graph/tree.hpp"
// HLD euler tour をとっていろいろ。
template <typename GT>
struct Tree {
using Graph_type = GT;
GT &G;
using WT = typename GT::cost_type;
int N;
vector<int> LID, RID, head, V, parent, VtoE;
vc<int> depth;
vc<WT> depth_weighted;
Tree(GT &G, int r = 0, bool hld = 1) : G(G) { build(r, hld); }
void build(int r = 0, bool hld = 1) {
if (r == -1) return; // build を遅延したいとき
N = G.N;
LID.assign(N, -1), RID.assign(N, -1), head.assign(N, r);
V.assign(N, -1), parent.assign(N, -1), VtoE.assign(N, -1);
depth.assign(N, -1), depth_weighted.assign(N, 0);
assert(G.is_prepared());
int t1 = 0;
dfs_sz(r, -1, hld);
dfs_hld(r, t1);
}
void dfs_sz(int v, int p, bool hld) {
auto &sz = RID;
parent[v] = p;
depth[v] = (p == -1 ? 0 : depth[p] + 1);
sz[v] = 1;
int l = G.indptr[v], r = G.indptr[v + 1];
auto &csr = G.csr_edges;
// 使う辺があれば先頭にする
for (int i = r - 2; i >= l; --i) {
if (hld && depth[csr[i + 1].to] == -1) swap(csr[i], csr[i + 1]);
}
int hld_sz = 0;
for (int i = l; i < r; ++i) {
auto e = csr[i];
if (depth[e.to] != -1) continue;
depth_weighted[e.to] = depth_weighted[v] + e.cost;
VtoE[e.to] = e.id;
dfs_sz(e.to, v, hld);
sz[v] += sz[e.to];
if (hld && chmax(hld_sz, sz[e.to]) && l < i) { swap(csr[l], csr[i]); }
}
}
void dfs_hld(int v, int ×) {
LID[v] = times++;
RID[v] += LID[v];
V[LID[v]] = v;
bool heavy = true;
for (auto &&e: G[v]) {
if (depth[e.to] <= depth[v]) continue;
head[e.to] = (heavy ? head[v] : e.to);
heavy = false;
dfs_hld(e.to, times);
}
}
vc<int> heavy_path_at(int v) {
vc<int> P = {v};
while (1) {
int a = P.back();
for (auto &&e: G[a]) {
if (e.to != parent[a] && head[e.to] == v) {
P.eb(e.to);
break;
}
}
if (P.back() == a) break;
}
return P;
}
int heavy_child(int v) {
int k = LID[v] + 1;
if (k == N) return -1;
int w = V[k];
return (parent[w] == v ? w : -1);
}
int e_to_v(int eid) {
auto e = G.edges[eid];
return (parent[e.frm] == e.to ? e.frm : e.to);
}
int v_to_e(int v) { return VtoE[v]; }
int get_eid(int u, int v) {
if (parent[u] != v) swap(u, v);
assert(parent[u] == v);
return VtoE[u];
}
int ELID(int v) { return 2 * LID[v] - depth[v]; }
int ERID(int v) { return 2 * RID[v] - depth[v] - 1; }
// 目標地点へ進む個数が k
int LA(int v, int k) {
assert(k <= depth[v]);
while (1) {
int u = head[v];
if (LID[v] - k >= LID[u]) return V[LID[v] - k];
k -= LID[v] - LID[u] + 1;
v = parent[u];
}
}
int la(int u, int v) { return LA(u, v); }
int LCA(int u, int v) {
for (;; v = parent[head[v]]) {
if (LID[u] > LID[v]) swap(u, v);
if (head[u] == head[v]) return u;
}
}
int meet(int a, int b, int c) { return LCA(a, b) ^ LCA(a, c) ^ LCA(b, c); }
int lca(int u, int v) { return LCA(u, v); }
int subtree_size(int v, int root = -1) {
if (root == -1) return RID[v] - LID[v];
if (v == root) return N;
int x = jump(v, root, 1);
if (in_subtree(v, x)) return RID[v] - LID[v];
return N - RID[x] + LID[x];
}
int dist(int a, int b) {
int c = LCA(a, b);
return depth[a] + depth[b] - 2 * depth[c];
}
WT dist_weighted(int a, int b) {
int c = LCA(a, b);
return depth_weighted[a] + depth_weighted[b] - WT(2) * depth_weighted[c];
}
// a is in b
bool in_subtree(int a, int b) { return LID[b] <= LID[a] && LID[a] < RID[b]; }
int jump(int a, int b, ll k) {
if (k == 1) {
if (a == b) return -1;
return (in_subtree(b, a) ? LA(b, depth[b] - depth[a] - 1) : parent[a]);
}
int c = LCA(a, b);
int d_ac = depth[a] - depth[c];
int d_bc = depth[b] - depth[c];
if (k > d_ac + d_bc) return -1;
if (k <= d_ac) return LA(a, k);
return LA(b, d_ac + d_bc - k);
}
vc<int> collect_child(int v) {
vc<int> res;
for (auto &&e: G[v])
if (e.to != parent[v]) res.eb(e.to);
return res;
}
vc<int> collect_light(int v) {
vc<int> res;
bool skip = true;
for (auto &&e: G[v])
if (e.to != parent[v]) {
if (!skip) res.eb(e.to);
skip = false;
}
return res;
}
vc<pair<int, int>> get_path_decomposition(int u, int v, bool edge) {
// [始点, 終点] の"閉"区間列。
vc<pair<int, int>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
down.eb(LID[head[v]], LID[v]);
v = parent[head[v]];
} else {
up.eb(LID[u], LID[head[u]]);
u = parent[head[u]];
}
}
if (LID[u] < LID[v]) down.eb(LID[u] + edge, LID[v]);
elif (LID[v] + edge <= LID[u]) up.eb(LID[u], LID[v] + edge);
reverse(all(down));
up.insert(up.end(), all(down));
return up;
}
// 辺の列の情報 (frm,to,str)
// str = "heavy_up", "heavy_down", "light_up", "light_down"
vc<tuple<int, int, string>> get_path_decomposition_detail(int u, int v) {
vc<tuple<int, int, string>> up, down;
while (1) {
if (head[u] == head[v]) break;
if (LID[u] < LID[v]) {
if (v != head[v]) down.eb(head[v], v, "heavy_down"), v = head[v];
down.eb(parent[v], v, "light_down"), v = parent[v];
} else {
if (u != head[u]) up.eb(u, head[u], "heavy_up"), u = head[u];
up.eb(u, parent[u], "light_up"), u = parent[u];
}
}
if (LID[u] < LID[v]) down.eb(u, v, "heavy_down");
elif (LID[v] < LID[u]) up.eb(u, v, "heavy_up");
reverse(all(down));
concat(up, down);
return up;
}
vc<int> restore_path(int u, int v) {
vc<int> P;
for (auto &&[a, b]: get_path_decomposition(u, v, 0)) {
if (a <= b) {
FOR(i, a, b + 1) P.eb(V[i]);
} else {
FOR_R(i, b, a + 1) P.eb(V[i]);
}
}
return P;
}
// path [a,b] と [c,d] の交わり. 空ならば {-1,-1}.
// https://codeforces.com/problemset/problem/500/G
pair<int, int> path_intersection(int a, int b, int c, int d) {
int ab = lca(a, b), ac = lca(a, c), ad = lca(a, d);
int bc = lca(b, c), bd = lca(b, d), cd = lca(c, d);
int x = ab ^ ac ^ bc, y = ab ^ ad ^ bd; // meet(a,b,c), meet(a,b,d)
if (x != y) return {x, y};
int z = ac ^ ad ^ cd;
if (x != z) x = -1;
return {x, x};
}
};
#line 2 "/home/maspy/compro/library/ds/unionfind/unionfind.hpp"
struct UnionFind {
int n, n_comp;
vc<int> dat; // par or (-size)
UnionFind(int n = 0) { build(n); }
void build(int m) {
n = m, n_comp = m;
dat.assign(n, -1);
}
void reset() { build(n); }
int operator[](int x) {
while (dat[x] >= 0) {
int pp = dat[dat[x]];
if (pp < 0) { return dat[x]; }
x = dat[x] = pp;
}
return x;
}
ll size(int x) {
x = (*this)[x];
return -dat[x];
}
bool merge(int x, int y) {
x = (*this)[x], y = (*this)[y];
if (x == y) return false;
if (-dat[x] < -dat[y]) swap(x, y);
dat[x] += dat[y], dat[y] = x, n_comp--;
return true;
}
vc<int> get_all() {
vc<int> A(n);
FOR(i, n) A[i] = (*this)[i];
return A;
}
};
#line 3 "/home/maspy/compro/library/graph/functional.hpp"
// N が根となる木を新たに作る
template <typename T = int>
struct FunctionalGraph {
int N, M;
vc<int> TO;
vc<T> wt;
vc<int> root;
Graph<T, 1> G;
FunctionalGraph() {}
FunctionalGraph(int N) : N(N), M(0), TO(N, -1), wt(N), root(N, -1) {}
void add(int a, int b, T c = 1) {
assert(0 <= a && a < N);
assert(TO[a] == -1);
++M;
TO[a] = b;
wt[a] = c;
}
pair<Graph<T, 1>, Tree<Graph<T, 1>>> build() {
assert(N == M);
UnionFind uf(N);
FOR(v, N) if (!uf.merge(v, TO[v])) { root[v] = v; }
FOR(v, N) if (root[v] == v) root[uf[v]] = v;
FOR(v, N) root[v] = root[uf[v]];
G.build(N + 1);
FOR(v, N) {
if (root[v] == v)
G.add(N, v, wt[v]);
else
G.add(TO[v], v, wt[v]);
}
G.build();
Tree<Graph<T, 1>> tree(G, N);
return {G, tree};
}
// a -> b にかかる回数. 不可能なら infty<int>. O(1).
template <typename TREE>
int dist(TREE& tree, int a, int b) {
if (tree.in_subtree(a, b)) return tree.depth[a] - tree.depth[b];
int r = root[a];
int btm = TO[r];
// a -> r -> btm -> b
if (tree.in_subtree(btm, b)) {
int x = tree.depth[a] - tree.depth[r];
x += 1;
x += tree.depth[btm] - tree.depth[b];
return x;
}
return infty<int>;
}
// functional graph に向かって進む
template <typename TREE>
int jump(TREE& tree, int v, ll step) {
int d = tree.depth[v];
if (step <= d - 1) return tree.jump(v, N, step);
v = root[v];
step -= d - 1;
int bottom = TO[v];
int c = tree.depth[bottom];
step %= c;
if (step == 0) return v;
return tree.jump(bottom, N, step - 1);
}
// functional graph に step 回進む
template <typename TREE>
vc<int> jump_all(TREE& tree, ll step) {
vc<int> res(N, -1);
// v の k 個先を res[w] に入れる
vvc<pair<int, int>> query(N);
FOR(v, N) {
int d = tree.depth[v];
int r = root[v];
if (d - 1 > step) { query[v].eb(v, step); }
if (d - 1 <= step) {
ll k = step - (d - 1);
int bottom = TO[r];
int c = tree.depth[bottom];
k %= c;
if (k == 0) {
res[v] = r;
continue;
}
query[bottom].eb(v, k - 1);
}
}
vc<int> path;
auto dfs = [&](auto& dfs, int v) -> void {
path.eb(v);
for (auto&& [w, k]: query[v]) { res[w] = path[len(path) - 1 - k]; }
for (auto&& e: G[v]) dfs(dfs, e.to);
path.pop_back();
};
for (auto&& e: G[N]) { dfs(dfs, e.to); }
return res;
}
template <typename TREE>
bool in_cycle(TREE& tree, int v) {
int r = root[v];
int bottom = TO[r];
return tree.in_subtree(bottom, v);
}
vc<int> collect_cycle(int r) {
assert(r == root[r]);
vc<int> cyc = {TO[r]};
while (cyc.back() != r) cyc.eb(TO[cyc.back()]);
return cyc;
}
};
#line 5 "main.cpp"
const int MAX_N = 200000;
int single[MAX_N][4];
// [i][j] := i からスタートして 10j 文字読んだ
int table[MAX_N][21];
void solve() {
LL(H, W, K);
vc<int> A(K, -1);
{
STR(S);
FOR(k, K) {
if (S[k] == 'D') A[k] = 0;
if (S[k] == 'R') A[k] = 1;
if (S[k] == 'U') A[k] = 2;
if (S[k] == 'L') A[k] = 3;
assert(A[k] != -1);
}
}
vv(int, idx, H, W, -1);
ll N = 0;
FOR(x, H) {
STR(t);
FOR(y, W) {
if (t[y] == '0') continue;
idx[x][y] = N++;
}
}
auto isin = [&](int x, int y) -> bool { return (0 <= x && x < H && 0 <= y && y < W); };
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
FOR(x, H) FOR(y, W) {
if (idx[x][y] == -1) continue;
FOR(d, 4) {
single[idx[x][y]][d] = idx[x][y];
int x1 = x + dx[d], y1 = y + dy[d];
if (!isin(x1, y1)) continue;
if (idx[x1][y1] == -1) continue;
single[idx[x][y]][d] = idx[x1][y1];
}
}
// もうグリッドはわすれてよい
FunctionalGraph<int> FG(N);
FOR(i, N) {
vc<int> path;
path.eb(i);
for (auto &a: A) { path.eb(single[path.back()][a]); }
FOR(n, len(path)) {
if (n % 10 == 0) { table[i][n / 10] = path[n]; }
}
FG.add(i, path[K]);
}
auto [G, tree] = FG.build();
// NK ステップ先
vc<int> END(N);
FOR(v, N) END[v] = FG.jump(tree, v, N);
// 合流する時刻 / 合流する直前の頂点
// 合流しないならば [NK] での何か
auto compare = [&](int i, int j) -> tuple<ll, int, int> {
assert(i != j);
if (FG.root[i] != FG.root[j]) { return {infty<ll>, END[i], END[j]}; }
// 同じサイクルには入ります
int r = FG.root[i];
int b = FG.TO[r];
ll n = tree.depth[b] - tree.depth[r] + 1; // cyc len
if ((tree.depth[i] - tree.depth[j]) % n != 0) { return {infty<ll>, END[i], END[j]}; }
// そのうち交わります
ll t = infty<ll>;
if (tree.depth[i] == tree.depth[j]) {
int lca = tree.lca(i, j);
t = tree.depth[i] - tree.depth[lca];
} else {
// 両方サイクルに入ったら
ll ti = tree.depth[i] - tree.depth[tree.lca(b, i)];
ll tj = tree.depth[j] - tree.depth[tree.lca(b, j)];
t = max(ti, tj);
}
// 時刻 tK は合流済です
ll x = FG.jump(tree, i, t - 1);
ll y = FG.jump(tree, j, t - 1);
assert(x != y && FG.TO[x] == FG.TO[y]);
int p = 0;
while (10 * (p + 1) <= K && table[x][p + 1] != table[y][p + 1]) ++p;
x = table[x][p], y = table[y][p];
p *= 10;
while (single[x][A[p]] != single[y][A[p]]) {
x = single[x][A[p]];
y = single[y][A[p]];
++p;
}
return {K * (t - 1) + p + 1, x, y};
};
vc<int> ord(N);
FOR(v, N) ord[v] = v;
sort(all(ord), [&](auto &i, auto &j) -> bool {
if (i == j) return 0;
auto [t, x, y] = compare(i, j);
return x < y;
});
vi merge;
FOR(i, N - 1) {
int v = ord[i], w = ord[i + 1];
auto [t, x, y] = compare(v, w);
if (t == infty<ll>) continue;
merge.eb(t);
}
vi ANS(N + 1, infty<ll>);
ANS[N] = 0;
sort(all(merge));
ll n = len(merge);
FOR(i, n) ANS[N - 1 - i] = merge[i];
while (len(ANS) < H * W + 1) ANS.eb(0);
ANS.erase(ANS.begin());
for (auto &x: ANS)
if (x == infty<ll>) x = -1;
for (auto &x: ANS) print(x);
}
signed main() {
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5788kb
input:
3 3 6 ULDDRR 010 111 010
output:
-1 4 2 1 0 0 0 0 0
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
3 3 6 ULDDRR 010 111 011
output:
7 4 2 1 1 0 0 0 0
result:
ok 9 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5784kb
input:
1 5 1 R 11111
output:
4 3 2 1 0
result:
ok 5 number(s): "4 3 2 1 0"
Test #4:
score: 0
Accepted
time: 344ms
memory: 55040kb
input:
1 200000 200 RDRLDRULURDLDRULLRULLRRULRULRDLLDLRUDDLRURLURLULDRUUURDLUDUDLLLLLURRDURLUDDRRLRRURUUDDLLDDUUUDUULRLRUDULRRUURUDDDDLULULLLLLLLLLLLUDURLURLRLLRRRURUURLUDULDUULRRLULLRUDRDRUUDDRUDRDLLDLURDDDURLUULDRRDLDD 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
3999923 3999865 3999864 3999740 3999729 3999728 3999727 3999726 3999725 3999724 3999723 3999665 3999664 3999540 3999529 3999528 3999527 3999526 3999525 3999524 3999523 3999465 3999464 3999340 3999329 3999328 3999327 3999326 3999325 3999324 3999323 3999265 3999264 3999140 3999129 3999128 3999127 3999...
result:
ok 200000 numbers
Test #5:
score: 0
Accepted
time: 421ms
memory: 55436kb
input:
2 100000 200 UULDRDLURDLDDRDRDUULDLUUULLRURLUUDDDRURURLLRRUDLDDDUDDRRUUURDDULURURLRULLUDLULURUUDURLDRRRDULRDLRRLDUUUDDUUDUDRDRUDLDRRUDRDLDRDLDRRDLRRDRDLRRLUDUDRULLRRLDDLUDDULDRLLLDLURRDDULDDUDULLRRRUURLRRRLURDLRLU 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 384513 384490 384313 384290 384113 384090 383913 383890 383713 383690 383513 383490 383313 383290 383113 383090 382913 382890 382713 382690 382513 382490 382313 382290 382113 382090 381913 381890 381713 381690 381513 381490 381313 381290 381113 381090 380...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 370ms
memory: 54788kb
input:
5 40000 200 URDDRRUDURLDLUUDUUDDLRRRURULURDRRURRURULUULRRLDLLDUURRDRUULRULULUDRURRRURDDLLDDRLLLUDUDLLDDULUUUULDLDUDLULLDRURRDRDULURLLLUDLRRRDRLUDDUURULURRRDLDRUDLURUUULDLURDDDRRLLLDLRRDLDLDRRURRRRDLRRLLULRRLDUULD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1000036 999836 999636 999436 999236 999036 998836 998636 998436 998236 998036 997836 997636 997436 997236 997036 996836 996636 996436 996236 996036 995836 995636 995436 995236 995036 994836 994636 994436 994236 994036 993836 993636 993436 993236 993036 992836 992636 992436 992236 992036 991836 99163...
result:
ok 200000 numbers
Test #7:
score: 0
Accepted
time: 419ms
memory: 54640kb
input:
10 20000 200 UULRURURUDRUULRRRDDDULUURRDUURDLDLLURRDUDDRDULRDURLDDLRRRRRRURLLUUURURDDUDDLLRDRLDDDDRULDRLLDUDLLLUDRURLDDLRRULDRRLLRRRDLRUDDDRRLDLRUDRUUDDDLUDULLDLUDUDUUUDLLRUURRLRLLDLLLLRLLRRDRRLLUDDURDRRDDULLDDULR 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
571658 571458 571258 571058 570858 570658 570458 570258 570058 569858 569658 569458 569258 569058 568858 568658 568458 568258 568058 567858 567658 567458 567258 567058 566858 566658 566458 566258 566058 565858 565658 565458 565258 565058 564858 564658 564458 564258 564058 563858 563658 563458 563258...
result:
ok 200000 numbers
Test #8:
score: 0
Accepted
time: 462ms
memory: 54316kb
input:
20 10000 200 UUDUUDRDLLLURLULDRULUDLRURRUUDLDLUURUDURDRUULULULUURRDDDLUDLLRDDLDULLDURLRRUULLRDULUUDDLRDLDRDLDULULRLLLLUDUUUDDLDLLRLUUDLURLULLURDDDLLLUDDDLRDULLUUDRLDLRDLRLURRUUDLRULURRLLLURRUDLDUDRLUDDRDUUULLDDUDL 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
83411 83305 83211 83105 83011 82905 82811 82705 82611 82505 82411 82305 82211 82105 82011 81905 81811 81705 81611 81505 81411 81305 81211 81105 81011 80905 80811 80705 80611 80505 80411 80305 80211 80105 80011 79905 79811 79705 79611 79505 79411 79305 79211 79105 79011 78905 78811 78705 78611 78505 ...
result:
ok 200000 numbers
Test #9:
score: 0
Accepted
time: 452ms
memory: 55212kb
input:
50 4000 200 LUDLUULUUUDUDDUDRULLDDRDRDLDUDRUUDUUUDULDUURDUUDLRUDDDURURRRUDDRUDDRURURURUDLLLDRURLLRRURRLULDDLLURULRDURDDLURURDDURDDRURRDDDULUURLUDRRUULRLURUDULLRURUUDLRDDLULUDRULDRRLRRLURDLUDDRDRLRRDDULRULDLURRRUL 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
53472 53272 53072 52872 52672 52472 52272 52072 51872 51672 51472 51272 51072 50872 50672 50472 50272 50072 49872 49672 49472 49272 49072 48872 48672 48472 48272 48072 47872 47672 47472 47272 47072 46872 46672 46472 46272 46072 45872 45672 45472 45272 45072 44872 44672 44472 44272 44072 43872 43672 ...
result:
ok 200000 numbers
Test #10:
score: 0
Accepted
time: 479ms
memory: 55424kb
input:
100 2000 200 UDULUDLDUUDDUDLURDRDLDDLLDRLLDUURUDLLUURLRLLRDLUUUURLLUDRRUDUDDLRLLLDDUUDDULRUUULLRRUUUUUDRLLUUUURDUDLUUDLUDDRRULRLRLUDLRLRRRLRULULLRLLURRUUUDRLRRRRLUURULURUUUUDURRDDDRLLLLULDUDRLDURUUDDRRRULULRLRDULD 10111111111111111111111111111111111111111111111111111111111111111110111111111100111111...
output:
-1 -1 47281 47081 46881 46681 46481 46281 46081 45881 45681 45481 45281 45081 44881 44681 44481 44281 44081 43881 43681 43481 43281 43081 42881 42681 42481 42281 42081 41881 41681 41481 41281 41081 40881 40681 40481 40281 40081 39881 39681 39481 39281 39081 38881 38681 38481 38281 38081 37881 37681 ...
result:
ok 200000 numbers
Test #11:
score: 0
Accepted
time: 548ms
memory: 54044kb
input:
200 1000 200 RLRDLDRDUDLRDULDLLURDULDLLDUDLULLLUUUDLRRRUDLUUUDDRLULRRLDLDLLDRLLLURDLDRRRLULUDDLUDUULULUULDRRURDDLUUULURULRUUDRRLRDULDUDRLDLRUDRLULLLLRLLDRDLDLRDUUUUUULUDLDRUDDUUDRLDRUDUUDLULLDDURLRULLRULDRLLRDLURR 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 10432 10232 10062 10032 9994 9887 9862 9832 9794 9687 9662 9632 9594 9487 9462 9432 9394 9287 9262 9232 9194 9087 9062 9032 8994 8887 8862 8832 8794 8687 8662 8632 8594 8487 8462 8432 8394 8287 8262 8232 8194 8135 8087 8062 8032 7994 7935 7887 7862 7832 7794 7736 7735 7687 7662 7632 7594 7553 753...
result:
ok 200000 numbers
Test #12:
score: 0
Accepted
time: 561ms
memory: 54532kb
input:
400 500 200 RULLRRRDLUDDRLDDRDLRLDLDLUUDRUDDULRDDLDULULLRUDULRLRLRUDURDRDDDLDRUDRLRDRLRDLULLLLRURRLRRULULDLDRDDULDDUULURLRLLDUUUUDDUDURLULRLDRLDDRULUDDLLRRDDULLDLURDLDRLLULRLRUULRLLLRULRUDLRRRLURUULLLDDDUDRDLRURD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
9541 9370 9369 9341 9244 9243 9170 9169 9141 9103 9044 9043 9039 9039 9022 8987 8970 8969 8960 8941 8903 8876 8865 8844 8843 8839 8839 8824 8822 8787 8770 8769 8760 8750 8741 8703 8676 8676 8665 8644 8643 8639 8639 8624 8622 8588 8587 8570 8569 8560 8550 8541 8503 8503 8476 8476 8465 8444 8443 8439 ...
result:
ok 200000 numbers
Test #13:
score: 0
Accepted
time: 515ms
memory: 54012kb
input:
447 447 200 LULRUURRDLDUDDRDRLDDUDLRLURUDLLDDLRLRDLURURRDRDDDRRDDLLDRDDDUDULLRLURLLURULLLLRUUULDRDRRDDULULRLURDDUDURDULUURRLDURURDDUDDDDURRLRLLDLULDRURDUUURLRULURUULURURUDDRDDDDLLRRLLLDRLRDDRRLDDRULLLLRURDRUULRUU 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 22650 22450 22250 22050 21850 21650 21450 21250 21050 20850 20650 20450 20250 ...
result:
ok 199809 numbers
Test #14:
score: 0
Accepted
time: 548ms
memory: 55960kb
input:
500 400 200 DUUDRULRRRULLDUDDULULLRRDUDRULDRUURUDLDLDDDDRDLDUDRLDLDDURUDDLDLLLRLURDRULDLRLDRRUDRRULURDLDDDLULRLLRRDLUDLLULUULLRLLUURLDDULLRRDDRULUDRRLRRDURLLLDRDRRRLUDUUDUDDLRUDUDLRLDRLURULUULDUDLLDURDLLDDLRLULLU 111111111111111111111111111111111111111111111111011111111111111111111111111111111111111...
output:
11256 11056 10856 10656 10456 10256 10056 9856 9656 9456 9256 9065 9056 8865 8856 8665 8656 8469 8465 8456 8269 8265 8256 8069 8065 8056 7918 7879 7869 7865 7856 7718 7679 7669 7665 7656 7518 7511 7479 7469 7465 7456 7434 7318 7311 7311 7279 7269 7265 7256 7234 7118 7111 7111 7094 7079 7069 7065 705...
result:
ok 200000 numbers
Test #15:
score: 0
Accepted
time: 415ms
memory: 55032kb
input:
1000 200 200 LRUURLUDLDRURRLRLDRDLURDRUDUULDRLULLLRURRURDLULDULDDUDUULRLRDRLRLUDURULRDLDDLUURULDURDLLRUUDURDLURDDDUDRURRDRUUUUDLRUULRDDRLULDURLRDURDLDRRULRURLRUDLRRUUDRRDDLLUULDDDRDLRURLDLRDDULDDDUUDDRURURDDLRRRDR 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 20999 20799 20599 20399 20199 19999 19799 19599 19399 19199 18999 18799 18599 18399 18199 17999 17799 17799 17599 ...
result:
ok 200000 numbers
Test #16:
score: 0
Accepted
time: 507ms
memory: 54756kb
input:
2000 100 200 LRLUUDDLLUURLDRUUDUDRRULRDRDURURLRLLLRDLULLDRRRULDUDRDDRRRDUUDDDRLLULDRULRDDLDUULRDUDLRUUUDRDLRLDDUDLLDLLUDDLDRLRLURURLRRRLUULLLDLRLULDRRRLURDRDLRUDDLLLLRUDRLRLLRUDRDLUDLDRDDDLDUDLRDUURDRDUDDDUUDURUUU 11111111111111111111111111111111111111111111111111111111111111111111101111111111111111...
output:
-1 -1 -1 -1 -1 41180 40980 40780 40580 40380 40180 39980 39780 39580 39380 39180 38980 38780 38580 38380 38180 37980 37780 37580 37380 37180 36980 36780 36580 36380 36180 35980 35780 35580 35380 35180 34980 34780 34580 34380 34180 33980 33780 33580 33380 33180 32980 32780 32580 32380 32180 31980 317...
result:
ok 200000 numbers
Test #17:
score: 0
Accepted
time: 376ms
memory: 56856kb
input:
4000 50 200 DRUDDUDULRURRULUUDLLUUURUURLLDUDRRUULULDLRRLUDURLRUDDLRRDLUDURUULRDRURUDUDRDLDUDLDURULURRLRRRDRDRRRDRDUDLUDRDUDLRLDDULLLLLUDRDLLUDRRRLUURDUULLRRLLRLDDLDRDDDUDLRRRURDRLLUDUUURLLDDLLRRLLDRUDRUULUULRURDR 11111111111111111111111111111111111111111111111111 111111111111111111111111111111111111...
output:
-1 112736 112536 112336 112136 111936 111736 111536 111336 111136 110936 110736 110536 110336 110136 109936 109736 109536 109336 109136 108936 108736 108536 108336 108136 107936 107736 107536 107336 107136 106936 106736 106536 106336 106136 105936 105736 105536 105336 105136 104936 104736 104536 104...
result:
ok 200000 numbers
Test #18:
score: 0
Accepted
time: 368ms
memory: 54728kb
input:
10000 20 200 UDLLURURULUUUDDLDRDRLDLRUULDLUUULUULLRRDUUDDLRDRRLUDUDLRRLUURLURRLULRRURLRRLLDLULUDRRDUUUDURRURLDDRRDRRDLDURDRLLURDDDDDURULRULULLUURLUDUUUUDDLURULRUDLUDDRLLUDRLDRRULUDRDUDRUDDDLLRRURULULDLLUDLLRUDRDRL 11111111111111111111 11111111111111111111 11111111111111111111 11111111111111111111 11...
output:
182271 182071 181871 181671 181471 181271 181071 180871 180671 180471 180271 180071 179871 179671 179471 179271 179071 178871 178671 178471 178271 178071 177871 177671 177471 177271 177071 176871 176671 176471 176271 176071 175871 175671 175471 175271 175071 174871 174671 174471 174271 174071 173871...
result:
ok 200000 numbers
Test #19:
score: 0
Accepted
time: 215ms
memory: 55752kb
input:
20000 10 200 RULRLRLLLRUUDLLDDUDUURUUUUDUUDDRDDUULRRLDRDDRRLUURRLUDUDURUDRUDLDLDDURLRDRRRRUDRDLRRRULLLDLRURRDUUURURUDUUUDLLLRDLDDDLRULUDDURRUUDDDLURLDURRRRDLLLDRUDDDULRRLRDURRDURDDUDDUDLDRLLLULLULRULULLRLUUDRLDLDL 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 1111111111 111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #20:
score: 0
Accepted
time: 350ms
memory: 55876kb
input:
40000 5 200 LDULRUULURUDRDLRUDUDURUUUDDRLUDDRUDUUUUDURUDUURDRLURLDURDUDRUULURUURRRRURRRLRLUUUULLLLDLDLRUUDDLDRLDURRRRUULDDLRRLRUUUDDRDRDRLLLLRDURLLLLDRRUULLDRLRULRURUDDURLDDRRRULUDULDULRDLDLRLRUUUDRLRRUUDLRULURRD 11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 11111 111...
output:
444424 444224 444024 443824 443624 443424 443224 443024 442824 442624 442424 442224 442024 441824 441624 441424 441224 441024 440824 440624 440424 440224 440024 439824 439624 439424 439224 439024 438824 438624 438424 438224 438024 437824 437624 437424 437224 437024 436824 436624 436424 436224 436024...
result:
ok 200000 numbers
Test #21:
score: 0
Accepted
time: 340ms
memory: 60364kb
input:
100000 2 200 RRULURDRDDUULLLURURULUDRRDLULURRULUURDURDRRLDDRLRDLRLURRDDDRRDRLDDLUDRLUDDLLUDRLDRURLLDDLRURRRLLLLUULRULUDRRLLLLRLLUUULURDDDRRDRDULLLUULLRDDRUDUURRRLURURDLULURLURLDLRULUDDDRULRUDRLUDLDLLLUURDDLRLLULUU 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11...
output:
-1 -1 -1 -1 -1 -1 -1 829117 828917 828717 828517 828317 828117 827917 827717 827517 827317 827117 826917 826717 826517 826317 826117 825917 825717 825517 825317 825117 824917 824717 824517 824317 824117 823917 823717 823517 823317 823117 822917 822717 822517 822317 822117 821917 821717 821517 821317...
result:
ok 200000 numbers
Test #22:
score: 0
Accepted
time: 321ms
memory: 65700kb
input:
200000 1 200 RUDRUUULRUDURLULRLLLRLDLLUURRLURRDDRLRLLDDUULDRURDLRRRLLLRRURURLDRUURLLRRRRLULLURLDULDLUURLLRUDLRRRRURLDRLLDDUUURDRUUULRLDRDLULRRUDRRDDDRLRDLUDLDUUULDDRUUDLULRDULLURUULLRULLUDDRDDLLRRUUUDULDLDRDLLDDDU 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
4444289 4444280 4444277 4444231 4444174 4444171 4444118 4444117 4444094 4444089 4444080 4444077 4444031 4443974 4443971 4443918 4443917 4443894 4443889 4443880 4443877 4443831 4443774 4443771 4443718 4443717 4443694 4443689 4443680 4443677 4443631 4443574 4443571 4443518 4443517 4443494 4443489 4443...
result:
ok 200000 numbers
Test #23:
score: 0
Accepted
time: 514ms
memory: 54376kb
input:
447 447 200 DRUDULRLDRLUUUDRRDULUDRUURRRLDRDUDULDRLRLUDLDRURDRDUULRRUDRRLDULLRRLDDRRDRLRDRLRLDDRRULDLRDRUDRUDDRRLRRULDDDLRLRURLLULLDLDDRDDULRULURDULDULULRURDLLLRUDUUUURUDRDRLRLDRURRLLLURDUDDDDULLRDRDUDLDULLRULLLD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
12700 12500 12485 12478 12474 12316 12300 12285 12278 12277 12274 12144 12116 12100 12085 12078 12077 12074 11944 11916 11900 11885 11878 11877 11874 11744 11716 11700 11685 11678 11677 11674 11544 11516 11500 11485 11478 11477 11474 11344 11316 11300 11285 11278 11277 11274 11144 11116 11100 11085 ...
result:
ok 199809 numbers
Test #24:
score: 0
Accepted
time: 424ms
memory: 52780kb
input:
447 447 200 RRUULDLLULUUDLDUUDDRLDUDLLDLUURDLDURLUDUDLRRDDDDUUULRDDRDURDDDLDRDDLRDDLULUDLURDDRUUDUUDUDLRRDRUDDUUDLRRUDLRDDLUUUDDURDLDDLULUURUURDDLLUDRDRDLLLRDRLUDLLRDUDRRRDURUDLLLUUUDULLRRUDRLLLDDLURUUDRLDDRUUURL 110111111111111111111111111111111111011111111111111111111111111111101111111101111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 12867 12667 12667 12467 12467 12267 12267 12067 12067 11867 118...
result:
ok 199809 numbers
Test #25:
score: 0
Accepted
time: 368ms
memory: 53048kb
input:
447 447 200 LULULUDRURRURLDRLUUDDLDUDRLLUDRLLLLDDUULLLLRLUDLRRLDRRRLURRULULURRRUULUUDRLUDDLRRDDRLLURLDDULLDURDULRRURULLRUURLUUUULULLDLRLDLULULDDRDUDRULUUDUUDRRRDRURUUDLDDRRLDLRLLULLRLURDDULRLUDLRLUDUDUDLLRRUULDDU 111101111111111101111111111110011111101101111111111111111111111111111111111001011101111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 9719 9519 9433 9319 9233 9119 9033 8919 8833 8719 8633 8519 8433 8319 8233 8130 8119 8033 7930 7919 7833 773...
result:
ok 199809 numbers
Test #26:
score: 0
Accepted
time: 142ms
memory: 34756kb
input:
447 447 200 UDUDDURLLULURDRLLDLLRDDRDRUDRRRURLRDRDDURURDUUDRUUDURDRLULLRLDDLRURUDDRDULDUDDRLLDDRRULURRUUDDURRURDRRLUDLRLLDLUUDDLUDUULLLLUULDURRDDRDDLULLULDRLRLLUURLDUDRUDDLUUULUDUUUDUUDLUDDRLDDDRRDUURUUDDDRDLRLRL 001100011110110011011100101110111101101001000011011010011001100100000111110101010100100...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 199809 numbers
Test #27:
score: 0
Accepted
time: 27ms
memory: 14420kb
input:
447 447 200 DRLLUUDDULDRRDDDLLRRLUDLUURULDLRUDULDLLLRLDLLUDUDDULRUULRDDLDLUDRDRUDRRLLDDUDLDLULLUULRDRDRUUURDRRRDRRUULLDUUDDDUDRUDLRLRRLRUDDURULUUULULDDRRRLRURDLRDLDRUUDRUUDRRLDLUULLRLURURRURLLDDLRRLRURLRURULUULLR 000010000000000000101000000000100000000000000000000000000000001000000000000000000000000...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 199809 numbers
Test #28:
score: 0
Accepted
time: 463ms
memory: 54584kb
input:
100 2000 200 DURRLLDURUUDULRRUDRRUDLURRDUURLUURLUDLRURLRLRRRURDDRULRRULLUUDUDRDLUDDRRDRRDULUDUDULDRDLRUUULLRLULURRRRDDRUULDLLDUDDRLDURLULURUDRLRDLULRDLLLDRLDULLRRDLDURDUURLDLLRLLDDURUDRDDLUURDURRULRRRDDLLRRDURRDDU 11110111111111111011111111111111111011111111111111110111111111111111111111111011111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 32875 32675 32475 32275 32075 31875 31675 31475 31275 31075 30875 30675 30475 30275 30075 29875 29675 29475 29275 29075 28875 28675 28475 28275 28075 27875 27675 27475 27275 27075 26875 26675 26475 26275 26075 25875 25675 25475 25275 25075 24875 24675 24475 242...
result:
ok 200000 numbers
Test #29:
score: 0
Accepted
time: 397ms
memory: 52780kb
input:
200 1000 200 UDDLRLLURDDRDLRURLUURDRRRUULUULLRDDLRRDUUDDULDDUULULLLRDRUUDRRULRDLLUUDURDLDUURLRDDUDRURDRLRUDRLURUULDRLURUURLRULUUULLLRUDDDLRULLLRRDULUDDURURUURDUUULDRURDDDULULRRULRLLULULLURDDLDRRULLLULDLUDLLRDDUDRL 11111111111111111111111111011111111111111111110111111111111111110111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 4972 4792 4772 4718 4592 4572 4518 4399 4392 4372 4359 4318 4207 4199...
result:
ok 200000 numbers
Test #30:
score: 0
Accepted
time: 393ms
memory: 52920kb
input:
400 500 200 URDRUUDRDUUDRRRUUDLDDLRRRLRULLRDDDULRURUURLLRDLULURRURRRLLRRLDUDLDRRRLLUUUDULLDRRDDRULULDUUDDRLRUURRRLDDRRUDRDDDDDLLURDLDUDDLRURLDRUUDUDRURURLDURRULDRLDDRLRLDLLUURUULRRRULLUDDLDRRDLDRRDRRURLURLDULDDLU 111111101111111111111111111111110111111101111011111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 8513 8434 8353 8313 8234 8153 8113 8034 7953 7953 7913 7900 7834 7753 7753 7713 7700 7634 7553 7553 7553 7513 7500 7434 7398 7358 7353 7353 7353 7352 7313 7300 7234 7198 7158 7153 7153 7153...
result:
ok 200000 numbers
Test #31:
score: 0
Accepted
time: 408ms
memory: 52776kb
input:
500 400 200 LRLLDDDLLRRLLRDURRLLDLUDLLRDRULRURULUDURRUDDRLRDRLURRDURLLLDLRUDRDLUURUDDUUDUUDUURRLDRURLDULDRLLLDDUUUULRDLUDURLLRDRRLUDLLRLURUULUURDRULLDDDLRDLRUURDUUDRDLDRURDDURUDUDRUUUDURUUDURDUUDURLDDRUDDDRLRLRDR 111111111111101101111111011111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #32:
score: 0
Accepted
time: 454ms
memory: 54016kb
input:
1000 200 200 RLRDURLUDDLRRURLUDRLUUURULRLLULRRRRUDLRRDLUULDRDURLDLURLUDULLRDLRLDLRUDLLRRULLUUDDRRDUUULUDLRLDUDLUURDUUURRUULRLRLUUDLLLULUDLRLDUUUURDUDRRDLRDLRRLRULDDRULURDUULULLUDDLLUDRURURRUDRUDLDRLRLDLUULLRUUUUDD 11111111110111111101111111110111111111111111011111111111111110101111111110111111011111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11932 11732 11725 11596 11532 11525 11520 11396 11393 11332 11325 11320 11196 11193 11132 11125 11120 10996 10993 10932 10925 10920 10829 10796 10793 10732 10725 10720 10629 10596 10593 10532 10525 10520 10429 10396 10393 10332 10325 10320 10229 10196 10193 ...
result:
ok 200000 numbers
Test #33:
score: 0
Accepted
time: 340ms
memory: 54012kb
input:
2000 100 200 RLDDDLUDDURRDLURDUULDRDUURDULDDRLLRUDDULDDRURDUULLDDDUULDDRUUDRUUDLLLULRRDRULRUDURRRRDULRRLUUDRULRRUURURDUDULULDLLLUDDLLLURRDRRRDDDDRUULDLULUULURLLDDUUDRUDDRDDLLDUDRDDDLUUURRLLUUUDLLURURURRLUUUDUUDDUL 01111111111101111111110111111111111111011111111111111111111111111111111111111111101111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #34:
score: 0
Accepted
time: 350ms
memory: 52292kb
input:
100 2000 200 UDDRLDUDRDRLLLRDLRLDLDULLULUUULDUUULULLDDDLLULRDLURLUUULRDRRLURURLULLLDULRUULURUDRDLRUDUDURUUUDDRLUDDRUDUUUUDURUDUURDRLURLDURDUDRUULURUURRRRURRRLRLUUUULLLLDLDLRUUDDLDRLDURRRRUULDDLRRLRUUUDDRDRDRLLLLRD 11111111111111111111111111111011011111111011111110111111111111100111111110111111110111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #35:
score: 0
Accepted
time: 360ms
memory: 51408kb
input:
200 1000 200 ULRLUUDDRLUURDRRDULLDDULLLDLRULRRRRULRULLDRDRUUDLDLLLRUULRDUDLRDRLRUDDUDULUULDLUURLRRUUURRDURLDLRUURUDULRDUDLDULLURRURURULDLDDRDRRUURRULRLDURRLLDRUDDUURLLLRRLDLRDDRLRUULLDLRLDDRUUDRUULRDRDLDULULLULLDU 11111111111111111111111111111111111111111111111111111111101111101111111111111110111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #36:
score: 0
Accepted
time: 322ms
memory: 51508kb
input:
400 500 200 RURRDRUULDRLDRRLLRURRLUDLRURLLRLDRLURURLDLDLUULDURDLDUULDDULRDUULRDLURDDUURRDRULDRLRLUURUURLUUURRURDDRDDRUUDLULRDDDULULLLUDLDDRRLRUDDULLUDUDLDRLUUURLLULRLRDURLUDLDRDLDDDRRLDURLLDLRDDDRRDUURRRRRRDDRLUD 111111100111111111111111111111111111111111101110111101111011111110101111111111111110101...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #37:
score: 0
Accepted
time: 398ms
memory: 51100kb
input:
500 400 200 DUULDRURLULRULDLULUURLLUDRUDRULUDULUUDUUURUDUDRLLDLLRRDDDDLRRLRURLULDURRLULULLULLDUDLUUUUDRRRDUDDDDLLUDLRRLUURUULRULDRLDLLRURDRURDDULDLRRLLLDLRUULUURRRLUURLDLLURRULLURDLRDDDLLURLRRUURDDULLRDDDRLRLUURD 011110111111111111101111101111111111111111110111111011111111111111111111111111111010011...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11623 114...
result:
ok 200000 numbers
Test #38:
score: 0
Accepted
time: 335ms
memory: 52936kb
input:
1000 200 200 RRDDDLLDLLDUDURDLRDURUDDRUULLDLURUDDULLDLLRDRURLLLUULLUURDUDURUURURUUUURRUDRDRRLRRULRDULUUURLRRRULULDDDURDRURDRURLRRRRRDDLDRUDDDDLDDDURRURLRLUUDURRDRRRRLLLDRLUULURRLDUULUDUDLDRLRRLULRRRURDLDRLRDDRRDLR 01111111111111111111101111111011111111111111111111111101111111111011111111111110111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #39:
score: 0
Accepted
time: 394ms
memory: 52396kb
input:
2000 100 200 LRRDLURLLDLUULULRRRURURRRULRLLDURRDLUDUURUDUUURDUURULLDUUDURLDRLULUDRDUUULDRDURRDUURURUUDRDDRLDRDRRLLRDRDDDUDLRRRRDRRLRDRURDUDRRLLLLDRLULRDRRRRLURLLLRRDURLRDRDUUUDRUDURURLUULULLLURLLLULUURRRUULUDRULDU 11111111111111101111110100111111011111111111110110111111111111111111110011111110111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 26086 25886 25686 25486 25286 25086 24886 24686 24486 24286 24086 23886 23686 23486 23286 23086 22886 22686 22486 22286 22086 21886 21686 21486 21286 21086 20886 20686 20486 20286 20086 19886 19686 19486 19286 19086 188...
result:
ok 200000 numbers
Test #40:
score: 0
Accepted
time: 144ms
memory: 36752kb
input:
66663 3 200 RUDLLUDRLUDRLDURRDULRDULLDDRUDLLDURLDURLUDRLUDRLDURRUDLRDULRUDLRDULLUDRRUDLRDULRDULRDULLUDRLDURLDURRUDLLUDRRUDLLDURRDULLUDRLUDRRDULRDULUDRUDLLUDRRDULLUDRRDULRDULLDURLUDRRUDLLDURRUULDURRDULLUDRLUDRRUDL 011 010 011 010 011 010 011 010 011 010 011 010 011 010 011 010 011 010 011 010 011 010...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 199989 numbers
Test #41:
score: 0
Accepted
time: 239ms
memory: 49644kb
input:
66666 3 200 RURRLUUUULDLDRRRURURRLRULDLLRRRULURURULDUUDDDUURDRDLDRUUDLLUUULDDULULLLLLDLURUDURLDDDULRLDURRLURULRLDDURUDUDRDDLDDLLULDDLLLLDUDRDRLLRUDUULDLLRLLDDLRURRLURUDLUDUDDDUURDLRLDURRDRLRRDRDRLDDLLUDRRRRURRLUU 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101 101...
output:
-1 -1 -1 -1 13320869 13320681 13320669 13320481 13320469 13320281 13320269 13320081 13320069 13319881 13319869 13319681 13319669 13319481 13319469 13319281 13319269 13319081 13319069 13318881 13318869 13318681 13318669 13318481 13318469 13318281 13318269 13318081 13318069 13317881 13317869 13317681 ...
result:
ok 199998 numbers
Test #42:
score: 0
Accepted
time: 212ms
memory: 63636kb
input:
200000 1 200 LRLLRRLLRLRRLRLLRRLRLLRRLLLLRLLRRRRRLRRLLRRLLLLLRLLRRRRRLRLLRLRLLRRRRLRLLRRLRLRLRRRRLLLLRRRRLRRLLRLRLLLLRLLRLLRLRRRLRLLLLRLLLLLLLLLLLRRRLRLRRRLRRRRLLRLLRLRLRRRLLRLRLLRLLRRLLLRLLLRRRRLRRRRLLLRRRRRRRRLR 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #43:
score: 0
Accepted
time: 200ms
memory: 63676kb
input:
200000 1 200 DUDDUUUDDUUDUUUUDDDDUDDUDUDUUDDDUUDUUDUUUUUDDUDUDUUDDDUUUUDUUDDDDUDDUDDUDDDDUUUUUDUUUUUDUDUDDDDUUDUDDDDUDDUUUDUUDDDUDUUDUDUDDDUDDDDDUDUDUUDUUUDUUDDDUUDUDUDUUDDUUDDUUDDUUUUDUUUDDDDDDUUDUUDDUUDUUDUDDUDD 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 200000 numbers
Test #44:
score: 0
Accepted
time: 149ms
memory: 45028kb
input:
4 49999 200 RRRUUUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDULLDD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 199996 numbers
Test #45:
score: 0
Accepted
time: 152ms
memory: 42512kb
input:
4 49999 200 RRRUUUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDULLDD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 199996 numbers
Extra Test:
score: 0
Extra Test Passed