QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716223 | #7737. Extending Distance | maspy | AC ✓ | 10ms | 4236kb | C++23 | 38.9kb | 2024-11-06 14:41:56 | 2024-11-06 14:41:56 |
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_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(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>
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/flow/mincostflow.hpp"
// atcoder library のものを改変
namespace internal {
template <class E>
struct csr {
vector<int> start;
vector<E> elist;
explicit csr(int n, const vector<pair<int, E>>& edges) : start(n + 1), elist(edges.size()) {
for (auto e: edges) { start[e.first + 1]++; }
for (int i = 1; i <= n; i++) { start[i] += start[i - 1]; }
auto counter = start;
for (auto e: edges) { elist[counter[e.first]++] = e.second; }
}
};
template <class T>
struct simple_queue {
vector<T> payload;
int pos = 0;
void reserve(int n) { payload.reserve(n); }
int size() const { return int(payload.size()) - pos; }
bool empty() const { return pos == int(payload.size()); }
void push(const T& t) { payload.push_back(t); }
T& front() { return payload[pos]; }
void clear() {
payload.clear();
pos = 0;
}
void pop() { pos++; }
};
} // namespace internal
/*
・atcoder library をすこし改変したもの
・DAG = true であれば、負辺 OK (1 回目の最短路を dp で行う)
ただし、頂点番号は toposort されていることを仮定している。
*/
template <class Cap = int, class Cost = ll, bool DAG = false>
struct Min_Cost_Flow {
public:
Min_Cost_Flow() {}
explicit Min_Cost_Flow(int n, int source, int sink) : n(n), source(source), sink(sink) {
assert(0 <= source && source < n);
assert(0 <= sink && sink < n);
assert(source != sink);
}
// frm, to, cap, cost
int add(int frm, int to, Cap cap, Cost cost) {
assert(0 <= frm && frm < n);
assert(0 <= to && to < n);
assert(0 <= cap);
assert(DAG || 0 <= cost);
if (DAG) assert(frm < to);
int m = int(_edges.size());
_edges.push_back({frm, to, cap, 0, cost});
return m;
}
void debug() {
print("flow graph");
print("frm, to, cap, cost");
for (auto&& [frm, to, cap, flow, cost]: _edges) { print(frm, to, cap, cost); }
}
struct edge {
int frm, to;
Cap cap, flow;
Cost cost;
};
edge get_edge(int i) {
int m = int(_edges.size());
assert(0 <= i && i < m);
return _edges[i];
}
vector<edge> edges() { return _edges; }
// (流量, 費用)
pair<Cap, Cost> flow() { return flow(infty<Cap>); }
// (流量, 費用)
pair<Cap, Cost> flow(Cap flow_limit) { return slope(flow_limit).back(); }
vector<pair<Cap, Cost>> slope() { return slope(infty<Cap>); }
vector<pair<Cap, Cost>> slope(Cap flow_limit) {
int m = int(_edges.size());
vector<int> edge_idx(m);
auto g = [&]() {
vector<int> degree(n), redge_idx(m);
vector<pair<int, _edge>> elist;
elist.reserve(2 * m);
for (int i = 0; i < m; i++) {
auto e = _edges[i];
edge_idx[i] = degree[e.frm]++;
redge_idx[i] = degree[e.to]++;
elist.push_back({e.frm, {e.to, -1, e.cap - e.flow, e.cost}});
elist.push_back({e.to, {e.frm, -1, e.flow, -e.cost}});
}
auto _g = internal::csr<_edge>(n, elist);
for (int i = 0; i < m; i++) {
auto e = _edges[i];
edge_idx[i] += _g.start[e.frm];
redge_idx[i] += _g.start[e.to];
_g.elist[edge_idx[i]].rev = redge_idx[i];
_g.elist[redge_idx[i]].rev = edge_idx[i];
}
return _g;
}();
auto result = slope(g, flow_limit);
for (int i = 0; i < m; i++) {
auto e = g.elist[edge_idx[i]];
_edges[i].flow = _edges[i].cap - e.cap;
}
return result;
}
// O(F(N+M)) くらい使って経路復元
vvc<int> path_decomposition() {
vvc<int> TO(n);
for (auto&& e: edges()) { FOR(e.flow) TO[e.frm].eb(e.to); }
vvc<int> res;
vc<int> vis(n);
while (!TO[source].empty()) {
vc<int> path = {source};
vis[source] = 1;
while (path.back() != sink) {
int to = POP(TO[path.back()]);
while (vis[to]) { vis[POP(path)] = 0; }
path.eb(to), vis[to] = 1;
}
for (auto&& v: path) vis[v] = 0;
res.eb(path);
}
return res;
}
vc<Cost> get_potentials() { return potential; }
private:
int n, source, sink;
vector<edge> _edges;
// inside edge
struct _edge {
int to, rev;
Cap cap;
Cost cost;
};
vc<Cost> potential;
vector<pair<Cap, Cost>> slope(internal::csr<_edge>& g, Cap flow_limit) {
if (DAG) assert(source == 0 && sink == n - 1);
vector<pair<Cost, Cost>> dual_dist(n);
vector<int> prev_e(n);
vector<bool> vis(n);
struct Q {
Cost key;
int to;
bool operator<(Q r) const { return key > r.key; }
};
vector<int> que_min;
vector<Q> que;
auto dual_ref = [&]() {
for (int i = 0; i < n; i++) { dual_dist[i].second = infty<Cost>; }
fill(vis.begin(), vis.end(), false);
que_min.clear();
que.clear();
// que[0..heap_r) was heapified
size_t heap_r = 0;
dual_dist[source].second = 0;
que_min.push_back(source);
while (!que_min.empty() || !que.empty()) {
int v;
if (!que_min.empty()) {
v = que_min.back();
que_min.pop_back();
} else {
while (heap_r < que.size()) {
heap_r++;
push_heap(que.begin(), que.begin() + heap_r);
}
v = que.front().to;
pop_heap(que.begin(), que.end());
que.pop_back();
heap_r--;
}
if (vis[v]) continue;
vis[v] = true;
if (v == sink) break;
Cost dual_v = dual_dist[v].first, dist_v = dual_dist[v].second;
for (int i = g.start[v]; i < g.start[v + 1]; i++) {
auto e = g.elist[i];
if (!e.cap) continue;
Cost cost = e.cost - dual_dist[e.to].first + dual_v;
if (dual_dist[e.to].second > dist_v + cost) {
Cost dist_to = dist_v + cost;
dual_dist[e.to].second = dist_to;
prev_e[e.to] = e.rev;
if (dist_to == dist_v) {
que_min.push_back(e.to);
} else {
que.push_back(Q{dist_to, e.to});
}
}
}
}
if (!vis[sink]) { return false; }
for (int v = 0; v < n; v++) {
if (!vis[v]) continue;
dual_dist[v].first -= dual_dist[sink].second - dual_dist[v].second;
}
return true;
};
auto dual_ref_dag = [&]() {
FOR(i, n) dual_dist[i].se = infty<Cost>;
dual_dist[source].se = 0;
fill(vis.begin(), vis.end(), false);
vis[0] = true;
FOR(v, n) {
if (!vis[v]) continue;
Cost dual_v = dual_dist[v].fi, dist_v = dual_dist[v].se;
for (int i = g.start[v]; i < g.start[v + 1]; i++) {
auto e = g.elist[i];
if (!e.cap) continue;
Cost cost = e.cost - dual_dist[e.to].fi + dual_v;
if (dual_dist[e.to].se > dist_v + cost) {
vis[e.to] = true;
Cost dist_to = dist_v + cost;
dual_dist[e.to].second = dist_to;
prev_e[e.to] = e.rev;
}
}
}
if (!vis[sink]) { return false; }
for (int v = 0; v < n; v++) {
if (!vis[v]) continue;
dual_dist[v].fi -= dual_dist[sink].se - dual_dist[v].se;
}
return true;
};
Cap flow = 0;
Cost cost = 0, prev_cost_per_flow = -1;
vector<pair<Cap, Cost>> result = {{Cap(0), Cost(0)}};
while (flow < flow_limit) {
if (DAG && flow == 0) {
if (!dual_ref_dag()) break;
} else {
if (!dual_ref()) break;
}
Cap c = flow_limit - flow;
for (int v = sink; v != source; v = g.elist[prev_e[v]].to) { c = min(c, g.elist[g.elist[prev_e[v]].rev].cap); }
for (int v = sink; v != source; v = g.elist[prev_e[v]].to) {
auto& e = g.elist[prev_e[v]];
e.cap += c;
g.elist[e.rev].cap -= c;
}
Cost d = -dual_dist[source].first;
flow += c;
cost += c * d;
if (prev_cost_per_flow == d) { result.pop_back(); }
result.push_back({flow, cost});
prev_cost_per_flow = d;
}
dual_ref();
potential.resize(n);
FOR(v, n) potential[v] = dual_dist[v].fi;
return result;
}
};
#line 2 "/home/maspy/compro/library/flow/bflow.hpp"
template <class Flow = ll, class Cost = ll>
struct MinCostFlow {
private:
static constexpr int SCALING_FACTOR = 2;
using V_id = uint32_t;
using E_id = uint32_t;
struct Edge {
friend struct MinCostFlow;
private:
V_id frm, to;
Flow flow, cap;
Cost cost;
E_id rev;
public:
Edge() = default;
Edge(const V_id frm, const V_id to, const Flow cap, const Cost cost,
const E_id rev)
: frm(frm), to(to), flow(0), cap(cap), cost(cost), rev(rev) {}
[[nodiscard]] Flow residual_cap() const { return cap - flow; }
};
public:
struct EdgePtr {
friend struct MinCostFlow;
private:
const MinCostFlow *instance;
const V_id v;
const E_id e;
EdgePtr(const MinCostFlow *instance, const V_id v, const E_id e)
: instance(instance), v(v), e(e) {}
[[nodiscard]] const Edge &edge() const { return instance->g[v][e]; }
[[nodiscard]] const Edge &rev() const {
const Edge &e = edge();
return instance->g[e.to][e.rev];
}
public:
[[nodiscard]] V_id frm() const { return rev().to; }
[[nodiscard]] V_id to() const { return edge().to; }
[[nodiscard]] Flow flow() const { return edge().flow; }
[[nodiscard]] Flow lower() const { return -rev().cap; }
[[nodiscard]] Flow upper() const { return edge().cap; }
[[nodiscard]] Cost cost() const { return edge().cost; }
[[nodiscard]] Cost gain() const { return -edge().cost; }
};
private:
V_id n;
std::vector<std::vector<Edge>> g;
std::vector<Flow> b;
public:
MinCostFlow(int n) : n(n) {
g.resize(n);
b.resize(n);
}
V_id add_vertex() {
++n;
g.resize(n);
b.resize(n);
return n - 1;
}
std::vector<V_id> add_vertices(const size_t size) {
std::vector<V_id> ret;
for (V_id i = 0; i < size; ++i) ret.emplace_back(n + i);
n += size;
g.resize(n);
b.resize(n);
return ret;
}
void add(const V_id frm, const V_id to, const Flow lo, const Flow hi,
const Cost cost) {
const E_id e = g[frm].size(), re = frm == to ? e + 1 : g[to].size();
assert(lo <= hi);
g[frm].emplace_back(Edge{frm, to, hi, cost, re});
g[to].emplace_back(Edge{to, frm, -lo, -cost, e});
edges.eb(EdgePtr{this, frm, e});
}
void add_source(const V_id v, const Flow amount) { b[v] += amount; }
void add_sink(const V_id v, const Flow amount) { b[v] -= amount; }
private:
static Cost constexpr unreachable = std::numeric_limits<Cost>::max();
Cost farthest;
vc<Cost> potential, dist;
vc<Edge *> parent;
pqg<pair<Cost, int>> pq;
vc<V_id> excess_vs, deficit_vs;
vc<EdgePtr> edges;
Edge &rev(const Edge &e) { return g[e.to][e.rev]; }
void push(Edge &e, const Flow amount) {
e.flow += amount;
g[e.to][e.rev].flow -= amount;
}
Cost residual_cost(const V_id frm, const V_id to, const Edge &e) {
return e.cost + potential[frm] - potential[to];
}
bool dual(const Flow delta) {
dist.assign(n, unreachable);
parent.assign(n, nullptr);
excess_vs.erase(
remove_if(all(excess_vs), [&](const V_id v) { return b[v] < delta; }),
end(excess_vs));
deficit_vs.erase(
remove_if(all(deficit_vs), [&](const V_id v) { return b[v] > -delta; }),
end(deficit_vs));
for (const auto v: excess_vs) pq.emplace(dist[v] = 0, v);
farthest = 0;
size_t deficit_count = 0;
while (!pq.empty()) {
const auto [d, u] = pq.top();
pq.pop();
if (dist[u] < d) continue;
farthest = d;
if (b[u] <= -delta) ++deficit_count;
if (deficit_count >= deficit_vs.size()) break;
for (auto &e: g[u]) {
if (e.residual_cap() < delta) continue;
const auto v = e.to;
const auto new_dist = d + residual_cost(u, v, e);
if (new_dist >= dist[v]) continue;
pq.emplace(dist[v] = new_dist, v);
parent[v] = &e;
}
}
pq = decltype(pq)();
for (V_id v = 0; v < n; ++v) {
potential[v] += std::min(dist[v], farthest);
}
return deficit_count > 0;
}
void primal(const Flow delta) {
for (const auto t: deficit_vs) {
if (dist[t] > farthest) continue;
Flow f = -b[t];
V_id v;
for (v = t; parent[v] != nullptr && f >= delta; v = parent[v]->frm) {
f = std::min(f, parent[v]->residual_cap());
}
f = std::min(f, b[v]);
if (f < delta) continue;
for (v = t; parent[v] != nullptr;) {
auto &e = *parent[v];
push(e, f);
const size_t u = parent[v]->frm;
parent[v] = nullptr;
v = u;
}
b[t] += f;
b[v] -= f;
}
}
void saturate_negative(const Flow delta) {
excess_vs.clear();
deficit_vs.clear();
for (auto &es: g)
for (auto &e: es) {
const Flow rcap = e.residual_cap();
const Cost rcost = residual_cost(e.frm, e.to, e);
if (rcost < 0 && rcap >= delta) {
push(e, rcap);
b[e.frm] -= rcap;
b[e.to] += rcap;
}
}
for (V_id v = 0; v < n; ++v)
if (b[v] != 0) { (b[v] > 0 ? excess_vs : deficit_vs).emplace_back(v); }
}
public:
std::pair<bool, i128> solve() {
potential.resize(n);
for (auto &es: g)
for (auto &e: es) {
const Flow rcap = e.residual_cap();
if (rcap < 0) {
push(e, rcap);
b[e.frm] -= rcap;
b[e.to] += rcap;
}
}
Flow inf_flow = 1;
for (const auto &es: g)
for (const auto &e: es) inf_flow = std::max(inf_flow, e.residual_cap());
Flow delta = 1;
while (delta <= inf_flow) delta *= SCALING_FACTOR;
for (delta /= SCALING_FACTOR; delta; delta /= SCALING_FACTOR) {
saturate_negative(delta);
while (dual(delta)) primal(delta);
}
i128 value = 0;
for (const auto &es: g)
for (const auto &e: es) { value += i128(e.flow) * e.cost; }
value /= 2;
if (excess_vs.empty() && deficit_vs.empty()) {
return {true, value};
} else {
return {false, value};
}
}
template <class T>
T get_result_value() {
T value = 0;
for (const auto &es: g)
for (const auto &e: es) { value += (T)(e.flow) * (T)(e.cost); }
value /= (T)2;
return value;
}
std::vector<Cost> get_potential() {
std::fill(potential.begin(), potential.end(), 0);
for (int i = 0; i < (int)n; i++)
for (const auto &es: g)
for (const auto &e: es)
if (e.residual_cap() > 0)
potential[e.to]
= std::min(potential[e.to], potential[e.frm] + e.cost);
return potential;
}
std::vector<EdgePtr> get_edges() { return edges; }
};
#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 3 "/home/maspy/compro/library/graph/shortest_path/dijkstra.hpp"
template <typename T, typename GT>
pair<vc<T>, vc<int>> dijkstra_dense(GT& G, int s) {
const int N = G.N;
vc<T> dist(N, infty<T>);
vc<int> par(N, -1);
vc<bool> done(N);
dist[s] = 0;
while (1) {
int v = -1;
T mi = infty<T>;
FOR(i, N) {
if (!done[i] && chmin(mi, dist[i])) v = i;
}
if (v == -1) break;
done[v] = 1;
for (auto&& e: G[v]) {
if (chmin(dist[e.to], dist[v] + e.cost)) par[e.to] = v;
}
}
return {dist, par};
}
template <typename T, typename GT, bool DENSE = false>
pair<vc<T>, vc<int>> dijkstra(GT& G, int v) {
if (DENSE) return dijkstra_dense<T>(G, v);
auto N = G.N;
vector<T> dist(N, infty<T>);
vector<int> par(N, -1);
using P = pair<T, int>;
priority_queue<P, vector<P>, greater<P>> que;
dist[v] = 0;
que.emplace(0, v);
while (!que.empty()) {
auto [dv, v] = que.top();
que.pop();
if (dv > dist[v]) continue;
for (auto&& e: G[v]) {
if (chmin(dist[e.to], dist[e.frm] + e.cost)) {
par[e.to] = e.frm;
que.emplace(dist[e.to], e.to);
}
}
}
return {dist, par};
}
// 多点スタート。[dist, par, root]
template <typename T, typename GT>
tuple<vc<T>, vc<int>, vc<int>> dijkstra(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);
using P = pair<T, int>;
priority_queue<P, vector<P>, greater<P>> que;
for (auto&& v: vs) {
dist[v] = 0;
root[v] = v;
que.emplace(T(0), v);
}
while (!que.empty()) {
auto [dv, v] = que.top();
que.pop();
if (dv > dist[v]) continue;
for (auto&& e: G[v]) {
if (chmin(dist[e.to], dist[e.frm] + e.cost)) {
root[e.to] = root[e.frm];
par[e.to] = e.frm;
que.push(mp(dist[e.to], e.to));
}
}
}
return {dist, par, root};
}
#line 7 "main.cpp"
/*
potential p[v]
距離を L 以上にしたい : L<=p[t]-p[s]
辺 (u,v,w)
伸ばす量 max(0,p[v]-p[u]-w)
- t から s に費用-L, 容量INF
- u から v に費用 w, 容量 1
これの循環流
*/
template <typename T = ll, bool DAG = false>
struct Longest_Shortest_Path {
int N, s, t;
T F, L, K;
bool solved;
vc<tuple<int, int, T, T>> dat;
vc<T> pot;
Longest_Shortest_Path(int N, int s, int t) : N(N), s(s), t(t), F(0), solved(0) {}
// 現在の長さ, 長さを+1するコスト
void add(int frm, int to, T length, T cost) {
assert(0 <= frm && frm < N && 0 <= to && to < N && !solved);
if (DAG) assert(frm < to);
dat.eb(frm, to, length, cost);
}
T init_dist() {
Graph<T, 1> G(N);
for (auto& [a, b, c, d]: dat) G.add(a, b, c);
G.build();
auto [dist, par] = dijkstra<T>(G, s);
return dist[t];
}
// 距離が L 以上になるようにせよ. return: min cost.
T solve_by_target_length(T target_length) {
L = target_length;
assert(!solved && L >= init_dist());
solved = 1;
Min_Cost_Flow<T, T, DAG> G(N, s, t);
for (auto& [a, b, length, cost]: dat) { G.add(a, b, cost, length); }
T ans = -infty<T>;
for (auto& [x, y]: G.slope()) {
if (chmax(ans, x * L - y)) F = x;
}
return K = ans;
}
// コストが K で最大距離にせよ. return: max dist.
T solve_by_cost(T K) {}
// frm, to, cost. add_edge 順.
vc<T> get_potentials() {
assert(solved);
if (len(pot)) return pot;
Min_Cost_Flow<T, T, DAG> G(N, s, t);
for (auto& [a, b, length, cost]: dat) { G.add(a, b, cost, length); }
G.flow(F);
pot = G.get_potentials();
Graph<T, 1> resG(N);
auto add = [&](int a, int b, T x) -> void {
x = x + pot[a] - pot[b];
resG.add(a, b, x);
};
for (auto& e: G.edges()) {
if (e.cap > e.flow) add(e.frm, e.to, e.cost);
if (e.flow > 0) add(e.to, e.frm, -e.cost);
}
add(s, t, L), add(t, s, -L);
resG.build();
vc<T> dist = dijkstra<ll>(resG, s).fi;
FOR(x, N) pot[x] += dist[x];
return pot;
}
// 変更後の長さ
vc<T> get_edges() {
get_potentials();
vc<T> res;
for (auto [frm, to, length, cost]: dat) { res.eb(max<T>(length, pot[to] - pot[frm])); }
return res;
}
};
void solve() {
LL(H, W, K);
ll N = H * W;
ll s = N, t = N + 1;
auto idx = [&](int x, int y) -> int {
if (y == 0) return s;
if (y == W - 1) return t;
return W * x + y;
};
Longest_Shortest_Path<ll, false> X(N + 2, s, t);
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};
VV(ll, A, H, W - 1);
VV(ll, B, H - 1, W);
vc<tuple<int, int, int>> pos;
FOR(x, H) {
FOR(y, W) {
FOR(d, 2) {
int x1 = x + dx[d], y1 = y + dy[d];
if (!isin(x, y)) continue;
if (!isin(x1, y1)) continue;
ll c = (d == 0 ? B[x][y] : A[x][y]);
X.add(idx(x, y), idx(x1, y1), c, 1);
X.add(idx(x1, y1), idx(x, y), c, 1);
pos.eb(d, x, y);
pos.eb(d, x, y);
}
}
}
ll init = X.init_dist();
ll cost = X.solve_by_target_length(init + K);
vi L = X.get_edges();
FOR(n, len(pos)) {
auto [t, x, y] = pos[n];
if (t == 0) chmax(B[x][y], L[n]);
if (t == 1) chmax(A[x][y], L[n]);
}
print(cost);
FOR(x, len(A)) print(A[x]);
FOR(x, len(B)) print(B[x]);
}
signed main() {
INT(T);
FOR(T) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3756kb
input:
2 3 4 6 2 1 15 7 1 9 13 3 2 3 6 1 2 5 2 15 3 3 3 3 1 1 2 2 3 3 1 1 1 2 2 2
output:
9 7 1 15 10 1 9 13 3 2 3 6 1 2 5 3 15 3 4 4 1 3 2 3 3 1 1 1 2 2 2
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 2ms
memory: 3940kb
input:
125 4 4 48 33 9 39 38 74 3 18 44 9 20 91 19 76 95 17 16 61 88 50 49 68 18 33 84 4 4 14 54 69 42 47 90 28 2 73 59 1 20 90 43 22 74 19 27 67 46 43 42 21 78 80 4 4 93 12 67 38 13 85 39 74 68 77 71 80 64 92 97 53 46 66 6 30 20 66 70 71 24 4 4 34 43 86 55 49 34 73 78 77 90 99 49 5 55 4 63 47 80 24 15 3 8...
output:
87 81 9 39 38 74 3 38 63 9 20 91 19 76 95 17 16 61 88 50 49 68 18 33 84 14 54 69 42 47 90 28 2 73 59 15 20 90 43 22 74 19 27 67 46 43 42 21 78 80 166 105 67 38 80 91 39 74 68 77 71 80 64 92 97 53 46 66 6 30 20 66 70 71 24 34 45 86 55 49 64 73 78 77 90 99 49 7 55 4 63 47 80 24 15 3 85 12 6 31 45 57 1...
result:
ok Correct. (125 test cases)
Test #3:
score: 0
Accepted
time: 2ms
memory: 3808kb
input:
80 5 5 97 10 18 14 13 17 15 16 11 15 10 14 15 12 17 12 15 12 11 15 15 19 19 13 19 19 19 17 10 10 19 12 13 18 11 20 12 17 14 13 12 5 5 65 13 15 13 20 18 19 13 20 10 19 18 17 19 19 11 14 12 18 11 10 18 14 18 19 18 20 11 17 11 17 16 13 19 18 13 16 14 17 11 18 5 5 3 15 10 10 18 17 17 17 14 13 15 15 19 1...
output:
473 105 18 14 13 108 15 16 11 111 10 14 15 106 17 12 15 109 11 15 15 19 19 13 19 19 19 17 10 10 19 12 13 18 11 20 12 17 14 13 12 271 68 15 13 20 64 19 13 20 62 19 18 17 72 19 11 14 77 18 11 10 18 14 18 19 18 20 11 17 11 17 16 13 19 18 13 16 14 17 11 18 3 18 10 10 18 17 17 17 14 13 15 15 19 10 18 16 ...
result:
ok Correct. (80 test cases)
Test #4:
score: 0
Accepted
time: 2ms
memory: 4068kb
input:
55 6 6 98 943830625 154853276 396311720 585129723 216006508 789713291 522861691 174874210 616414184 931597164 831871942 149821142 520941619 814161584 200419736 646044877 574761262 188910317 673355715 723256093 264106685 163628126 318085983 226850181 101764170 179381345 486537031 346100002 805792579 ...
output:
98 943830625 154853276 396311720 585129723 216006508 789713291 522861691 174874210 616414184 931597164 831871942 149821142 520941619 814161584 200419736 646044877 574761262 188910317 673355715 723256093 264106783 163628126 318085983 226850181 101764170 179381345 486537031 346100002 805792579 5081942...
result:
ok Correct. (55 test cases)
Test #5:
score: 0
Accepted
time: 2ms
memory: 3776kb
input:
55 6 6 96 16739843 17336211 10384494 17185421 10646458 18552039 13790956 13642043 10307995 14193711 19297204 12810329 18681558 18724838 16636750 11505737 19658923 19307194 12241535 15070027 16123862 17524159 19471242 14316479 10954501 10604286 17691735 17352365 14092770 19909253 11761060 19372581 16...
output:
96 16739843 17336211 10384494 17185421 10646458 18552135 13790956 13642043 10307995 14193711 19297204 12810329 18681558 18724838 16636750 11505737 19658923 19307194 12241535 15070027 16123862 17524159 19471242 14316479 10954501 10604286 17691735 17352365 14092770 19909253 11761060 19372581 16863139 ...
result:
ok Correct. (55 test cases)
Test #6:
score: 0
Accepted
time: 2ms
memory: 3732kb
input:
40 7 7 17 27500 8466 7754 5254 45204 36821 35457 23725 45494 26962 24728 31437 46232 38720 23756 17265 21004 25959 29727 6060 23244 45236 39610 23968 17068 14954 9745 28949 20957 30885 8272 49710 28660 17038 12058 48058 10306 5065 45011 25264 25765 17423 21072 22743 17503 11324 10214 6879 22253 1729...
output:
17 27517 8466 7754 5254 45204 36821 35457 23725 45494 26962 24728 31437 46232 38720 23756 17265 21004 25959 29727 6060 23244 45236 39610 23968 17068 14954 9745 28949 20957 30885 8272 49710 28660 17038 12058 48058 10306 5065 45011 25264 25765 17423 21072 22743 17503 11324 10214 6879 22253 17295 49299...
result:
ok Correct. (40 test cases)
Test #7:
score: 0
Accepted
time: 2ms
memory: 3884kb
input:
31 8 8 84 82373 175391 615535 844446 885043 54908 235817 174599 782716 140021 505505 551220 980613 844864 490309 720051 436451 436322 357173 349094 303200 428983 865478 890817 50236 172208 96832 261006 265321 413840 490656 677420 172238 872751 182871 957260 978182 971447 603592 37811 282590 470570 1...
output:
84 82373 175391 615535 844446 885043 54908 235817 174599 782716 140021 505505 551220 980613 844864 490309 720051 436451 436322 357173 349094 303200 428983 865478 890817 50236 172208 96832 261006 265321 413840 490656 677420 172238 872751 182871 957260 978182 971447 603592 37811 282590 470570 134946 3...
result:
ok Correct. (31 test cases)
Test #8:
score: 0
Accepted
time: 2ms
memory: 4092kb
input:
24 9 9 80 178 146 100 118 196 180 100 110 153 125 200 139 174 169 163 196 173 167 120 182 172 142 188 132 160 150 148 171 162 125 180 152 159 152 161 177 106 129 152 114 179 132 146 126 107 148 141 151 165 123 151 153 112 151 148 182 105 188 136 199 173 192 117 118 116 190 103 198 125 150 105 118 15...
output:
227 235 146 100 118 196 180 100 110 153 125 200 139 174 169 163 196 173 167 120 182 172 142 188 132 160 150 148 171 162 125 180 152 194 152 161 177 106 129 152 114 234 132 146 126 107 148 141 151 165 123 151 153 112 151 148 182 105 188 136 199 173 192 117 118 196 190 103 198 125 150 105 118 157 130 ...
result:
ok Correct. (24 test cases)
Test #9:
score: 0
Accepted
time: 2ms
memory: 3856kb
input:
20 10 10 91 90000001 90000000 90000001 90000000 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000001 90000001 90000000 90000001 90000001 90000001 90000001 90000001 90000001 90000001 90000000 90000000 90000000 90000001 90000000 90000000 90000000 90000001 90000001 90000001 90000000 ...
output:
886 90000091 90000000 90000001 90000000 90000001 90000000 90000000 90000001 90000000 90000087 90000001 90000001 90000001 90000000 90000001 90000001 90000001 90000001 90000091 90000001 90000001 90000000 90000000 90000000 90000001 90000000 90000000 90000087 90000001 90000001 90000001 90000000 90000001...
result:
ok Correct. (20 test cases)
Test #10:
score: 0
Accepted
time: 2ms
memory: 3872kb
input:
10 14 14 68 20 23 20 22 23 26 23 22 28 30 25 20 29 22 30 26 20 22 21 26 23 23 22 22 22 21 24 29 30 30 24 20 25 23 30 27 27 26 24 30 25 25 24 26 26 23 22 22 30 24 20 23 27 24 29 24 22 24 21 20 20 28 24 21 28 20 24 25 29 20 30 30 30 30 24 27 23 28 29 25 25 26 21 27 23 25 25 27 23 27 23 23 22 27 27 29 ...
output:
607 77 23 20 22 23 26 23 22 28 30 25 20 29 74 30 29 32 22 21 27 23 23 22 22 22 21 53 29 30 30 24 20 25 23 30 27 27 26 24 78 25 25 24 26 26 23 22 22 30 24 20 23 64 24 29 34 22 24 30 20 20 28 24 21 28 48 24 25 29 20 30 30 30 30 24 27 23 28 68 25 25 29 21 27 23 25 25 27 23 27 23 56 22 27 27 29 30 25 24...
result:
ok Correct. (10 test cases)
Test #11:
score: 0
Accepted
time: 2ms
memory: 4080kb
input:
10 10 20 79 1001 1003 1000 1003 1001 1003 1002 1003 1001 1003 1003 1000 1001 1001 1001 1002 1002 1003 1002 1001 1003 1001 1001 1001 1000 1003 1002 1000 1002 1001 1001 1003 1000 1001 1003 1001 1001 1000 1001 1003 1000 1002 1003 1003 1003 1001 1002 1002 1000 1002 1003 1001 1003 1000 1002 1000 1002 100...
output:
732 1069 1003 1000 1003 1001 1003 1002 1003 1001 1003 1003 1000 1001 1001 1001 1002 1002 1003 1002 1079 1003 1001 1001 1001 1000 1003 1002 1000 1002 1001 1001 1003 1000 1001 1003 1001 1001 1000 1071 1003 1000 1002 1003 1003 1003 1001 1002 1002 1000 1002 1003 1001 1003 1000 1002 1000 1002 1075 1003 1...
result:
ok Correct. (10 test cases)
Test #12:
score: 0
Accepted
time: 3ms
memory: 3916kb
input:
10 20 10 21 777601561 917773453 313011120 861769383 651010533 771534309 418153755 749795307 939533489 769621271 705696594 863041783 330858635 136276987 569175453 21935211 559486868 264609946 30013079 725693020 492377730 630078388 365743281 693415122 589281054 690370363 47310510 125777481 136448711 5...
output:
21 777601561 917773453 313011120 861769383 651010533 771534309 418153755 749795307 939533489 769621271 705696594 863041783 330858635 136276987 569175453 21935211 559486868 264609946 30013079 725693020 492377730 630078388 365743281 693415122 589281054 690370363 47310510 125777502 136448711 508925654 ...
result:
ok Correct. (10 test cases)
Test #13:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
24 6 2 37 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 18 13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:
222 38 38 38 38 38 38 1 1 1 1 1 1 1 1 1 1 117 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 1 1 ...
result:
ok Correct. (24 test cases)
Test #14:
score: 0
Accepted
time: 3ms
memory: 3816kb
input:
31 9 3 33 1 5 4 5 3 4 4 2 5 3 4 3 2 5 5 5 4 3 5 1 4 2 1 2 1 5 3 5 3 2 2 3 2 3 5 3 4 4 3 1 4 2 2 3 4 3 2 5 2 1 3 5 12 6 72 2 2 1 1 5 1 2 5 1 4 5 5 1 2 3 4 1 4 4 4 1 2 2 2 5 5 5 3 5 3 2 1 1 3 5 4 1 4 2 1 4 2 1 5 3 3 3 2 4 5 5 5 2 3 3 4 3 4 5 1 3 5 5 5 1 1 5 5 3 2 5 3 5 3 1 4 3 3 5 4 5 1 3 5 2 3 3 5 4 ...
output:
284 34 5 34 5 35 4 37 2 36 3 36 3 34 5 34 5 36 3 5 1 4 2 1 2 1 5 3 5 3 2 2 3 2 3 5 3 4 4 3 1 4 2 6 7 2 7 2 1 3 5 803 73 2 1 1 5 70 2 5 1 4 66 5 6 2 3 69 1 4 4 4 68 5 2 2 5 65 5 3 5 4 69 4 1 3 5 72 1 4 2 3 71 2 1 5 3 68 3 2 4 5 67 5 2 4 4 68 3 4 6 1 3 5 5 5 1 1 5 5 3 2 5 3 5 3 1 4 3 3 5 4 5 1 3 5 2 3...
result:
ok Correct. (31 test cases)
Test #15:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
27 14 3 50 998244355 998244354 998244353 998244355 998244355 998244354 998244353 998244353 998244353 998244354 998244353 998244354 998244355 998244353 998244354 998244354 998244355 998244354 998244354 998244354 998244355 998244355 998244354 998244355 998244354 998244355 998244354 998244353 998244354...
output:
670 998244402 998244354 998244401 998244355 998244402 998244354 998244403 998244353 998244402 998244354 998244402 998244354 998244403 998244353 998244402 998244354 998244402 998244354 998244402 998244354 998244401 998244355 998244401 998244355 998244401 998244355 998244403 998244353 998244354 998244...
result:
ok Correct. (27 test cases)
Test #16:
score: 0
Accepted
time: 2ms
memory: 3948kb
input:
23 20 8 97 65608 5872 94352 46988 59846 12493 44992 76156 71668 37922 41038 63074 89348 52169 86215 13124 34107 56625 89609 74457 68595 4701 48937 41711 40122 4771 27822 49478 44146 33934 94003 46579 70799 92669 73897 74846 46044 73186 49298 7012 81846 33315 73703 6101 59247 53180 31956 19735 66252 ...
output:
97 65608 5872 94352 46988 59846 12493 44992 76156 71668 37922 41038 63074 89348 52169 86215 13124 34107 56625 89609 74457 68595 4798 48937 41711 40122 4771 27822 49478 44146 33934 94003 46579 70799 92669 73897 74846 46044 73186 49298 7012 81846 33315 73703 6101 59247 53180 31956 19735 66252 16794 81...
result:
ok Correct. (23 test cases)
Test #17:
score: 0
Accepted
time: 3ms
memory: 4176kb
input:
19 8 19 24 902387291 907620818 994686428 993181541 945788800 985461854 930840176 976723143 978273460 908804932 947598154 948392387 906663045 945746194 935677070 906756920 944967394 995192049 971027077 958873510 947130283 938614195 938536007 978161927 948149370 943899083 936971628 979751238 924273778...
output:
24 902387315 907620818 994686428 993181541 945788800 985461854 930840176 976723143 978273460 908804932 947598154 948392387 906663045 945746194 935677070 906756920 944967394 995192049 971027077 958873510 947130283 938614195 938536007 978161927 948149370 943899083 936971628 979751238 924273778 9948463...
result:
ok Correct. (19 test cases)
Test #18:
score: 0
Accepted
time: 2ms
memory: 3932kb
input:
17 8 6 73 454 453 255 154 145 234 372 334 453 446 475 154 423 475 172 348 129 504 471 299 381 454 313 281 135 313 366 411 397 449 137 361 216 132 284 231 127 338 217 508 7722 2335 6535 3174 7625 7253 1724 4688 3487 5118 746 2569 1333 8705 5312 7854 7121 8830 1497 1091 1873 8673 7066 9654 6715 1904 6...
output:
73 454 453 255 154 145 234 372 334 453 446 475 154 423 475 172 348 129 504 471 299 381 454 313 281 135 313 366 411 397 449 210 361 216 132 284 231 127 338 217 508 7722 2335 6535 3174 7625 7253 1724 4688 3487 5118 746 2569 1333 8705 5312 7854 7121 8830 1497 1091 1873 8673 7066 9654 6715 1904 6931 130...
result:
ok Correct. (17 test cases)
Test #19:
score: 0
Accepted
time: 2ms
memory: 4236kb
input:
23 88 2 97 841315194 845068923 970975198 957201780 251777303 404708591 2727155 669564257 336704019 803214539 649487089 931208031 194958628 208113257 766983395 773886317 969081031 767526283 94213588 872004907 742843321 70045653 828417878 78044768 948026239 74041166 698029055 507301238 56824543 257615...
output:
97 841315194 845068923 970975198 957201780 251777303 404708591 2727252 669564257 336704019 803214539 649487089 931208031 194958628 208113257 766983395 773886317 969081031 767526283 94213588 872004907 742843321 70045653 828417878 78044768 948026239 74041166 698029055 507301238 56824543 257615587 9794...
result:
ok Correct. (23 test cases)
Test #20:
score: 0
Accepted
time: 2ms
memory: 3948kb
input:
19 2 75 29 919738918 817415784 547071389 765591923 840765371 272558012 857925393 355491607 630197873 232681522 488447662 651935225 655063717 94077244 436556672 393624718 961794361 486877806 959891293 894435244 411013650 92339205 12625243 190596368 124067993 451522398 927510612 174581723 914056251 79...
output:
29 919738918 817415784 547071389 765591923 840765371 272558012 857925393 355491607 630197873 232681522 488447662 651935225 655063717 94077244 436556672 393624718 961794361 486877806 959891293 894435244 411013650 92339205 12625243 190596368 124067993 451522398 927510612 174581723 914056251 791511418 ...
result:
ok Correct. (19 test cases)
Test #21:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
1 5 6 10 1 1 1 1 100 1 1 2 100 100 100 1 1 1 100 100 100 2 1 1 100 1 1 1 1 1 100 100 100 1 100 100 100 100 2 1 100 100 1 2 100 100 100 100 1 100 100 100 1
output:
10 1 1 1 1 100 2 1 2 100 100 100 1 10 1 100 100 100 2 1 1 100 1 1 1 1 1 100 100 100 1 100 100 100 100 2 1 100 100 1 2 100 100 100 100 1 100 100 100 1
result:
ok Correct. (1 test case)
Test #22:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
2 5 6 100 1 2 1 1 100 1 1 2 100 100 100 1 1 1 100 100 100 2 1 1 100 1 1 1 1 2 100 100 100 1 100 100 100 100 2 1 100 100 1 2 100 100 100 100 1 100 100 100 2 6 5 100 1 100 100 100 100 100 2 1 100 100 2 100 100 2 100 100 1 1 100 100 100 100 100 1 2 1 100 100 100 1 1 1 100 1 1 2 2 2 1 1 100 1 1 1 100 10...
output:
117 9 2 1 1 100 11 1 2 100 100 100 1 85 1 100 100 100 2 1 1 101 9 1 1 1 2 100 100 100 1 100 100 100 100 2 1 100 100 1 8 100 100 100 100 1 100 100 100 2 101 2 100 100 100 100 100 5 1 100 100 2 100 100 2 100 100 6 1 100 100 100 100 100 1 2 1 100 100 100 1 1 1 100 1 1 2 94 2 1 1 100 1 1 1 100 100 100 1 1
result:
ok Correct. (2 test cases)
Test #23:
score: 0
Accepted
time: 2ms
memory: 3720kb
input:
55 6 6 98 396311720 585129723 216006508 789713291 522861691 585129723 216006508 789713291 522861691 174874210 216006508 789713291 522861691 174874210 616414184 789713291 522861691 174874210 616414184 931597164 522861691 174874210 616414184 931597164 831871942 174874210 616414184 931597164 831871942 ...
output:
98 396311720 585129723 216006508 789713291 522861691 585129723 216006508 789713291 522861691 174874210 216006508 789713291 522861691 174874210 616414184 789713291 522861691 174874210 616414184 931597164 522861691 174874210 616414184 931597164 831871942 174874308 616414184 931597164 831871942 1498211...
result:
ok Correct. (55 test cases)
Test #24:
score: 0
Accepted
time: 1ms
memory: 4000kb
input:
55 6 6 96 10384494 17185421 10646458 18552039 13790956 17185421 10646458 18552039 13790956 13642043 10646458 18552039 13790956 13642043 10307995 18552039 13790956 13642043 10307995 14193711 13790956 13642043 10307995 14193711 19297204 13642043 10307995 14193711 19297204 12810329 10384494 17185421 10...
output:
96 10384494 17185421 10646458 18552039 13790956 17185421 10646458 18552039 13790956 13642043 10646554 18552039 13790956 13642043 10307995 18552039 13790956 13642043 10307995 14193711 13790956 13642043 10307995 14193711 19297204 13642043 10307995 14193711 19297204 12810329 10384494 17185421 10646458 ...
result:
ok Correct. (55 test cases)
Test #25:
score: 0
Accepted
time: 2ms
memory: 3800kb
input:
31 8 8 84 615535 844446 885043 54908 235817 174599 782716 844446 885043 54908 235817 174599 782716 140021 885043 54908 235817 174599 782716 140021 505505 54908 235817 174599 782716 140021 505505 551220 235817 174599 782716 140021 505505 551220 980613 174599 782716 140021 505505 551220 980613 844864 ...
output:
84 615535 844446 885043 54908 235817 174599 782716 844446 885043 54908 235817 174599 782716 140021 885043 54908 235817 174599 782716 140021 505505 54992 235817 174599 782716 140021 505505 551220 235817 174599 782716 140021 505505 551220 980613 174599 782716 140021 505505 551220 980613 844864 782716 ...
result:
ok Correct. (31 test cases)
Test #26:
score: 0
Accepted
time: 2ms
memory: 3792kb
input:
24 9 9 80 100 118 196 180 100 110 153 125 118 196 180 100 110 153 125 200 196 180 100 110 153 125 200 139 180 100 110 153 125 200 139 174 100 110 153 125 200 139 174 169 110 153 125 200 139 174 169 163 153 125 200 139 174 169 163 196 125 200 139 174 169 163 196 173 200 139 174 169 163 196 173 167 10...
output:
80 180 118 196 180 100 110 153 125 118 196 180 100 110 153 125 200 196 180 100 110 153 125 200 139 180 100 110 153 125 200 139 174 100 110 153 125 200 139 174 169 110 153 125 200 139 174 169 163 153 125 200 139 174 169 163 196 125 200 139 174 169 163 196 173 200 139 174 169 163 196 173 167 100 118 1...
result:
ok Correct. (24 test cases)
Test #27:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
20 10 10 91 90000001 90000000 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000000 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000001 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000001 90000001 90000000 90000000 90000001 90000000 90000001 ...
output:
895 90000092 90000000 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000091 90000001 90000000 90000000 90000001 90000000 90000001 90000001 90000001 90000091 90000000 90000000 90000001 90000000 90000001 90000001 90000001 90000001 90000091 90000000 90000001 90000000 90000001 90000001...
result:
ok Correct. (20 test cases)
Test #28:
score: 0
Accepted
time: 2ms
memory: 4140kb
input:
10 14 14 68 20 22 23 26 23 22 28 30 25 20 29 22 30 22 23 26 23 22 28 30 25 20 29 22 30 26 23 26 23 22 28 30 25 20 29 22 30 26 20 26 23 22 28 30 25 20 29 22 30 26 20 22 23 22 28 30 25 20 29 22 30 26 20 22 21 22 28 30 25 20 29 22 30 26 20 22 21 26 28 30 25 20 29 22 30 26 20 22 21 26 23 30 25 20 29 22 ...
output:
755 68 22 23 26 23 22 28 30 25 20 29 22 30 64 23 26 23 22 28 30 25 20 29 22 30 26 67 26 23 22 28 30 25 20 29 22 30 26 20 71 23 22 28 30 25 20 29 22 30 26 20 22 73 22 28 30 25 20 29 22 30 26 20 22 21 69 28 30 25 20 29 22 30 26 20 22 21 26 74 30 25 20 29 22 30 26 20 22 21 26 23 81 25 20 29 22 30 26 20...
result:
ok Correct. (10 test cases)
Test #29:
score: 0
Accepted
time: 2ms
memory: 3700kb
input:
178 3 3 53 5 2 4 5 4 2 2 5 1 3 3 1 2 2 90 2 1 2 4 4 5 77 2 3 5 5 5 5 5 3 1 4 4 5 5 3 3 5 2 3 5 4 2 4 4 5 2 3 5 2 4 5 3 3 3 57 4 3 5 3 1 1 5 4 2 1 5 4 2 4 54 4 3 4 3 3 4 1 3 3 5 5 4 89 1 2 3 2 3 3 1 5 1 1 5 4 4 4 4 2 5 1 3 1 1 1 1 5 5 4 3 4 5 3 4 3 3 71 2 2 2 4 3 5 2 1 1 3 1 3 2 2 28 4 5 5 3 2 4 67 2...
output:
155 57 2 54 5 57 2 2 5 1 3 3 1 179 91 91 2 4 301 78 3 5 5 78 5 5 3 78 4 4 5 80 3 3 5 2 3 5 4 2 4 4 5 2 3 5 2 4 5 3 160 56 3 56 3 58 1 5 4 2 1 5 4 107 57 3 4 57 3 4 1 3 3 5 432 90 2 3 89 3 3 88 5 2 86 5 4 87 4 4 2 5 1 3 1 1 1 1 5 5 4 3 4 5 3 4 207 72 3 71 4 70 5 2 1 1 3 1 3 55 32 32 5 3 132 69 2 2 68...
result:
ok Correct. (178 test cases)
Test #30:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
25 11 14 66 998244354 998244355 998244354 998244353 998244355 998244354 998244355 998244355 998244353 998244354 998244353 998244353 998244355 998244354 998244353 998244353 998244355 998244355 998244353 998244353 998244354 998244353 998244355 998244353 998244355 998244354 998244353 998244354 99824435...
output:
678 998244414 998244355 998244354 998244353 998244355 998244354 998244355 998244355 998244353 998244354 998244353 998244353 998244355 998244417 998244353 998244353 998244355 998244355 998244353 998244353 998244354 998244353 998244355 998244353 998244355 998244354 998244419 998244354 998244354 998244...
result:
ok Correct. (25 test cases)
Test #31:
score: 0
Accepted
time: 2ms
memory: 3960kb
input:
24 6 9 73 78341 926193143 45972 89662 44179 39258 14522 928569793 79027 37377 30172 71689 54024 923464835 924430887 51505 58776 28871 83814 38691 29833 97617 58712 28722 15902 86266 962252400 27827 905696913 918736501 95599 4669 958072131 65347 27295 68035 95757 92683 65837 2171 3624 17191 63486 455...
output:
73 78341 926193143 45972 89662 44179 39258 14522 928569793 79027 37377 30172 71689 54024 923464835 924430887 51505 58776 28871 83814 38691 29833 97617 58712 28722 15902 86266 962252400 27827 905696913 918736501 95599 4669 958072131 65347 27295 68035 95757 92683 65837 2171 3697 17191 63486 45593 3836...
result:
ok Correct. (24 test cases)
Test #32:
score: 0
Accepted
time: 3ms
memory: 3948kb
input:
25 11 9 68 988729312 978893803 906310688 920140739 959394993 998273729 949853986 924816006 990193010 966906539 937746446 937776039 977125396 935068953 909078120 915698548 43064 967374842 961307275 996408546 925562822 931560002 944384977 981282702 922700388 966488914 982858666 953842932 971076445 992...
output:
68 988729312 978893803 906310688 920140739 959394993 998273729 949853986 924816006 990193010 966906539 937746446 937776039 977125396 935068953 909078120 915698548 43064 967374842 961307275 996408546 925562822 931560002 944384977 981282702 922700388 966488914 982858666 953842932 971076445 992872616 9...
result:
ok Correct. (25 test cases)
Test #33:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
10 10 50 100 260372550 224370653 929271301 767967410 502284101 349384009 202940941 154783885 145644362 966077435 743845691 149769897 507435023 60468873 659673803 389434862 715266673 14605135 188587870 63000907 442355443 785843949 982378871 22199344 584430140 772755653 965473791 989314835 231680916 9...
output:
100 260372550 224370653 929271301 767967410 502284101 349384009 202940941 154783885 145644362 966077435 743845691 149769897 507435023 60468873 659673803 389434862 715266673 14605135 188587870 63000907 442355443 785843949 982378871 22199344 584430140 772755653 965473791 989314835 231680916 945511294 ...
result:
ok Correct. (10 test cases)
Test #34:
score: 0
Accepted
time: 10ms
memory: 4044kb
input:
10 50 10 100 423572185 145436731 764686000 600633655 441415910 169443508 700789417 229288916 127363250 639533552 227845034 620956056 445675721 622306776 556528832 409465277 277492953 36493847 435349083 314519935 612191794 418296475 601945295 813525152 956721741 827242520 676200660 129973732 11311289...
output:
100 423572185 145436731 764686000 600633655 441415910 169443508 700789417 229288916 127363250 639533552 227845034 620956056 445675721 622306776 556528832 409465277 277492953 36493847 435349083 314519935 612191794 418296475 601945295 813525152 956721741 827242520 676200660 129973732 113112898 8339529...
result:
ok Correct. (10 test cases)
Test #35:
score: 0
Accepted
time: 10ms
memory: 4028kb
input:
10 20 25 100 236319064 155794674 339813709 886024917 794289478 901052716 226506117 8788803 911893440 697579614 51349234 667886501 828088943 787487581 742960185 628606808 506112146 537589422 500076754 950636717 5354362 9412365 605409672 56983400 385937164 675984872 539434747 948264769 790467650 43340...
output:
100 236319064 155794674 339813709 886024917 794289478 901052716 226506117 8788803 911893440 697579614 51349234 667886501 828088943 787487581 742960185 628606808 506112146 537589422 500076754 950636717 5354362 9412365 605409672 56983400 385937164 675984872 539434747 948264769 790467650 433400290 8399...
result:
ok Correct. (10 test cases)
Test #36:
score: 0
Accepted
time: 6ms
memory: 4020kb
input:
10 25 20 100 90000254 90000042 90000073 90000730 90000827 90000755 90000252 90000268 90000739 90000086 90000095 90000941 90000949 90000931 90000696 90000502 90000250 90000492 90000583 90000647 90000476 90000372 90000296 90000374 90000595 90000720 90000922 90000985 90000474 90000983 90000381 90000961...
output:
100 90000254 90000042 90000073 90000730 90000827 90000755 90000252 90000268 90000739 90000086 90000095 90000941 90000949 90000931 90000696 90000502 90000250 90000492 90000583 90000647 90000476 90000372 90000296 90000374 90000595 90000720 90000922 90000985 90000474 90000983 90000381 90000961 90000417...
result:
ok Correct. (10 test cases)
Test #37:
score: 0
Accepted
time: 6ms
memory: 3940kb
input:
10 10 50 100 10000 10000 10000 10000 10003 10001 10005 10001 10003 10000 10005 10000 10002 10001 10005 10001 10000 10000 10003 10005 10001 10005 10004 10000 10003 10000 10005 10001 10002 10000 10002 10005 10002 10000 10005 10003 10002 10003 10001 10001 10003 10002 10004 10003 10000 10004 10003 10000...
output:
833 10096 10000 10000 10000 10003 10001 10005 10001 10003 10000 10005 10000 10002 10001 10005 10001 10000 10000 10003 10005 10001 10005 10004 10000 10003 10000 10005 10001 10002 10000 10002 10005 10002 10000 10005 10003 10002 10003 10001 10001 10003 10002 10004 10003 10000 10004 10003 10000 10004 10...
result:
ok Correct. (10 test cases)
Test #38:
score: 0
Accepted
time: 6ms
memory: 3868kb
input:
12 20 20 100 2 1 2 4 3 4 3 5 4 3 5 5 2 1 1 4 3 1 4 1 4 3 2 2 3 3 4 2 5 4 1 1 1 3 3 2 3 1 2 2 1 4 5 3 1 1 1 1 2 3 3 2 2 3 2 4 2 3 2 2 4 5 3 4 2 1 5 5 3 4 1 5 1 3 4 3 1 2 2 2 4 4 5 2 2 5 5 3 1 1 2 5 3 1 2 2 3 2 4 5 3 4 1 2 1 1 4 2 5 1 1 4 2 3 1 3 4 5 5 2 3 4 4 4 5 2 4 5 3 5 4 2 5 5 5 1 2 5 5 1 3 5 4 5...
output:
1637 80 1 5 4 3 4 3 5 4 3 5 5 2 1 1 4 3 1 4 76 4 7 2 6 3 3 4 2 5 4 5 3 1 3 3 2 3 2 77 2 4 4 8 4 1 4 1 5 5 3 3 2 4 3 2 4 2 76 2 3 4 5 4 4 5 1 5 5 3 4 1 5 1 3 4 3 74 3 4 3 4 4 5 3 2 5 5 6 1 4 3 5 3 2 2 69 3 5 4 5 5 4 4 2 4 6 4 2 6 1 5 4 2 3 68 3 4 5 5 3 3 4 4 4 5 2 4 5 3 5 4 2 5 67 5 2 2 5 5 4 3 5 4 5...
result:
ok Correct. (12 test cases)
Extra Test:
score: 0
Extra Test Passed