QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#289032 | #7860. Graph of Maximum Degree 3 | ucup-team987# | AC ✓ | 85ms | 16808kb | C++20 | 19.9kb | 2023-12-23 14:52:28 | 2023-12-23 14:52:29 |
Judging History
answer
/**
* date : 2023-12-23 15:52:21
* author : Nyaan
*/
#define NDEBUG
using namespace std;
// intrinstic
#include <immintrin.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// utility
namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U>
struct P : pair<T, U> {
template <typename... Args>
P(Args... args) : pair<T, U>(args...) {}
using pair<T, U>::first;
using pair<T, U>::second;
P &operator+=(const P &r) {
first += r.first;
second += r.second;
return *this;
}
P &operator-=(const P &r) {
first -= r.first;
second -= r.second;
return *this;
}
P &operator*=(const P &r) {
first *= r.first;
second *= r.second;
return *this;
}
template <typename S>
P &operator*=(const S &r) {
first *= r, second *= r;
return *this;
}
P operator+(const P &r) const { return P(*this) += r; }
P operator-(const P &r) const { return P(*this) -= r; }
P operator*(const P &r) const { return P(*this) *= r; }
template <typename S>
P operator*(const S &r) const {
return P(*this) *= r;
}
P operator-() const { return P{-first, -second}; }
};
using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;
constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;
template <typename T>
int sz(const T &t) {
return t.size();
}
template <typename T, typename U>
inline bool amin(T &x, U y) {
return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
return (x < y) ? (x = y, true) : false;
}
template <typename T>
inline T Max(const vector<T> &v) {
return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
return accumulate(begin(v), end(v), 0LL);
}
template <typename T>
int lb(const vector<T> &v, const T &a) {
return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
return upper_bound(begin(v), end(v), a) - begin(v);
}
constexpr long long TEN(int n) {
long long ret = 1, x = 10;
for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
return ret;
}
template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
return make_pair(t, u);
}
template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
vector<T> ret(v.size() + 1);
if (rev) {
for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
} else {
for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
}
return ret;
};
template <typename T>
vector<T> mkuni(const vector<T> &v) {
vector<T> ret(v);
sort(ret.begin(), ret.end());
ret.erase(unique(ret.begin(), ret.end()), ret.end());
return ret;
}
template <typename F>
vector<int> mkord(int N, F f) {
vector<int> ord(N);
iota(begin(ord), end(ord), 0);
sort(begin(ord), end(ord), f);
return ord;
}
template <typename T>
vector<int> mkinv(vector<T> &v) {
int max_val = *max_element(begin(v), end(v));
vector<int> inv(max_val + 1, -1);
for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
return inv;
}
vector<int> mkiota(int n) {
vector<int> ret(n);
iota(begin(ret), end(ret), 0);
return ret;
}
template <typename T>
T mkrev(const T &v) {
T w{v};
reverse(begin(w), end(w));
return w;
}
template <typename T>
bool nxp(T &v) {
return next_permutation(begin(v), end(v));
}
// 返り値の型は入力の T に依存
// i 要素目 : [0, a[i])
template <typename T>
vector<vector<T>> product(const vector<T> &a) {
vector<vector<T>> ret;
vector<T> v;
auto dfs = [&](auto rc, int i) -> void {
if (i == (int)a.size()) {
ret.push_back(v);
return;
}
for (int j = 0; j < a[i]; j++) v.push_back(j), rc(rc, i + 1), v.pop_back();
};
dfs(dfs, 0);
return ret;
}
// F : function(void(T&)), mod を取る操作
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I, const function<void(T &)> &f) {
T res = I;
for (; n; f(a = a * a), n >>= 1) {
if (n & 1) f(res = res * a);
}
return res;
}
// T : 整数型のときはオーバーフローに注意する
template <typename T>
T Power(T a, long long n, const T &I = T{1}) {
return Power(a, n, I, function<void(T &)>{[](T &) -> void {}});
}
template <typename T>
T Rev(const T &v) {
T res = v;
reverse(begin(res), end(res));
return res;
}
template <typename T>
vector<T> Transpose(const vector<T> &v) {
using U = typename T::value_type;
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
res[j][i] = v[i][j];
}
}
return res;
}
template <typename T>
vector<T> Rotate(const vector<T> &v, int clockwise = true) {
using U = typename T::value_type;
int H = v.size(), W = v[0].size();
vector res(W, T(H, U{}));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (clockwise) {
res[W - 1 - j][i] = v[i][j];
} else {
res[j][H - 1 - i] = v[i][j];
}
}
}
return res;
}
} // namespace Nyaan
// bit operation
namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
return _mm_popcnt_u64(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
} // namespace Nyaan
// inout
namespace Nyaan {
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
int s = (int)v.size();
for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v) is >> x;
return is;
}
istream &operator>>(istream &is, __int128_t &x) {
string S;
is >> S;
x = 0;
int flag = 0;
for (auto &c : S) {
if (c == '-') {
flag = true;
continue;
}
x *= 10;
x += c - '0';
}
if (flag) x = -x;
return is;
}
istream &operator>>(istream &is, __uint128_t &x) {
string S;
is >> S;
x = 0;
for (auto &c : S) {
x *= 10;
x += c - '0';
}
return is;
}
ostream &operator<<(ostream &os, __int128_t x) {
if (x == 0) return os << 0;
if (x < 0) os << '-', x = -x;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
if (x == 0) return os << 0;
string S;
while (x) S.push_back('0' + x % 10), x /= 10;
reverse(begin(S), end(S));
return os << S;
}
void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
cin >> t;
in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
cout << t;
if (sizeof...(u)) cout << sep;
out(u...);
}
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(7);
}
} iosetupnya;
} // namespace Nyaan
// debug
#ifdef NyaanDebug
#define trc(...) (void(0))
#else
#define trc(...) (void(0))
#endif
#ifdef NyaanLocal
#define trc2(...) (void(0))
#else
#define trc2(...) (void(0))
#endif
// macro
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
long long __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define in2(s, t) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i]); \
}
#define in3(s, t, u) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i]); \
}
#define in4(s, t, u, v) \
for (int i = 0; i < (int)s.size(); i++) { \
in(s[i], t[i], u[i], v[i]); \
}
#define die(...) \
do { \
Nyaan::out(__VA_ARGS__); \
return; \
} while (0)
namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }
//
template <uint32_t mod>
struct LazyMontgomeryModInt {
using mint = LazyMontgomeryModInt;
using i32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;
static constexpr u32 get_r() {
u32 ret = mod;
for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
return ret;
}
static constexpr u32 r = get_r();
static constexpr u32 n2 = -u64(mod) % mod;
static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
static_assert(r * mod == 1, "this code has bugs.");
u32 a;
constexpr LazyMontgomeryModInt() : a(0) {}
constexpr LazyMontgomeryModInt(const int64_t &b)
: a(reduce(u64(b % mod + mod) * n2)){};
static constexpr u32 reduce(const u64 &b) {
return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
}
constexpr mint &operator+=(const mint &b) {
if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator-=(const mint &b) {
if (i32(a -= b.a) < 0) a += 2 * mod;
return *this;
}
constexpr mint &operator*=(const mint &b) {
a = reduce(u64(a) * b.a);
return *this;
}
constexpr mint &operator/=(const mint &b) {
*this *= b.inverse();
return *this;
}
constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
constexpr bool operator==(const mint &b) const {
return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
}
constexpr bool operator!=(const mint &b) const {
return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
}
constexpr mint operator-() const { return mint() - mint(*this); }
constexpr mint operator+() const { return mint(*this); }
constexpr mint pow(u64 n) const {
mint ret(1), mul(*this);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
constexpr mint inverse() const {
int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
while (y > 0) {
t = x / y;
x -= t * y, u -= t * v;
tmp = x, x = y, y = tmp;
tmp = u, u = v, v = tmp;
}
return mint{u};
}
friend ostream &operator<<(ostream &os, const mint &b) {
return os << b.get();
}
friend istream &operator>>(istream &is, mint &b) {
int64_t t;
is >> t;
b = LazyMontgomeryModInt<mod>(t);
return (is);
}
constexpr u32 get() const {
u32 ret = reduce(a);
return ret >= mod ? ret - mod : ret;
}
static constexpr u32 get_mod() { return mod; }
};
using namespace std;
// コンストラクタの MAX に 「C(n, r) や fac(n) でクエリを投げる最大の n 」
// を入れると倍速くらいになる
// mod を超えて前計算して 0 割りを踏むバグは対策済み
template <typename T>
struct Binomial {
vector<T> f, g, h;
Binomial(int MAX = 0) {
assert(T::get_mod() != 0 && "Binomial<mint>()");
f.resize(1, T{1});
g.resize(1, T{1});
h.resize(1, T{1});
if (MAX > 0) extend(MAX + 1);
}
void extend(int m = -1) {
int n = f.size();
if (m == -1) m = n * 2;
m = min<int>(m, T::get_mod());
if (n >= m) return;
f.resize(m);
g.resize(m);
h.resize(m);
for (int i = n; i < m; i++) f[i] = f[i - 1] * T(i);
g[m - 1] = f[m - 1].inverse();
h[m - 1] = g[m - 1] * f[m - 2];
for (int i = m - 2; i >= n; i--) {
g[i] = g[i + 1] * T(i + 1);
h[i] = g[i] * f[i - 1];
}
}
T fac(int i) {
if (i < 0) return T(0);
while (i >= (int)f.size()) extend();
return f[i];
}
T finv(int i) {
if (i < 0) return T(0);
while (i >= (int)g.size()) extend();
return g[i];
}
T inv(int i) {
if (i < 0) return -inv(-i);
while (i >= (int)h.size()) extend();
return h[i];
}
T C(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
return fac(n) * finv(n - r) * finv(r);
}
inline T operator()(int n, int r) { return C(n, r); }
template <typename I>
T multinomial(const vector<I>& r) {
static_assert(is_integral<I>::value == true);
int n = 0;
for (auto& x : r) {
if (x < 0) return T(0);
n += x;
}
T res = fac(n);
for (auto& x : r) res *= finv(x);
return res;
}
template <typename I>
T operator()(const vector<I>& r) {
return multinomial(r);
}
T C_naive(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
T ret = T(1);
r = min(r, n - r);
for (int i = 1; i <= r; ++i) ret *= inv(i) * (n--);
return ret;
}
T P(int n, int r) {
if (n < 0 || n < r || r < 0) return T(0);
return fac(n) * finv(n - r);
}
// [x^r] 1 / (1-x)^n
T H(int n, int r) {
if (n < 0 || r < 0) return T(0);
return r == 0 ? 1 : C(n + r - 1, r);
}
};
//
using namespace Nyaan;
using mint = LazyMontgomeryModInt<998244353>;
// using mint = LazyMontgomeryModInt<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
Binomial<mint> C;
template <typename T>
struct edge {
int src, to;
T cost;
edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnweightedGraph = vector<vector<int>>;
// Input of (Unweighted) Graph
UnweightedGraph graph(int N, int M = -1, bool is_directed = false,
bool is_1origin = true) {
UnweightedGraph g(N);
if (M == -1) M = N - 1;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
if (is_1origin) x--, y--;
g[x].push_back(y);
if (!is_directed) g[y].push_back(x);
}
return g;
}
// Input of Weighted Graph
template <typename T>
WeightedGraph<T> wgraph(int N, int M = -1, bool is_directed = false,
bool is_1origin = true) {
WeightedGraph<T> g(N);
if (M == -1) M = N - 1;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
cin >> c;
if (is_1origin) x--, y--;
g[x].emplace_back(x, y, c);
if (!is_directed) g[y].emplace_back(y, x, c);
}
return g;
}
// Input of Edges
template <typename T>
Edges<T> esgraph(int N, int M, int is_weighted = true, bool is_1origin = true) {
Edges<T> es;
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
if (is_weighted)
cin >> c;
else
c = 1;
if (is_1origin) x--, y--;
es.emplace_back(x, y, c);
}
return es;
}
// Input of Adjacency Matrix
template <typename T>
vector<vector<T>> adjgraph(int N, int M, T INF, int is_weighted = true,
bool is_directed = false, bool is_1origin = true) {
vector<vector<T>> d(N, vector<T>(N, INF));
for (int _ = 0; _ < M; _++) {
int x, y;
cin >> x >> y;
T c;
if (is_weighted)
cin >> c;
else
c = 1;
if (is_1origin) x--, y--;
d[x][y] = c;
if (!is_directed) d[y][x] = c;
}
return d;
}
/**
* @brief グラフテンプレート
* @docs docs/graph/graph-template.md
*/
using namespace Nyaan;
void q() {
ini(N, M);
auto g = wgraph<int>(N, M);
mint ans = 0;
// 次数 1
ans += N;
trc2(ans);
set<pi> st;
// 次数 2
rep(i, N) {
rep(j, sz(g[i])) rep(k, j) {
if (g[i][j] == g[i][k]) {
if (i < g[i][j]) {
ans += 1;
st.emplace(i, g[i][j]);
st.emplace(g[i][j], i);
}
}
}
}
trc2(ans);
auto get_color = [&](int i, int j) {
each(e, g[i]) if (e == j) return e.cost;
return -1;
};
// 次数 3
rep(i, N) {
if (sz(g[i]) != 3) continue;
map<int, int> mp;
each(e, g[i]) mp[e]++;
if (sz(mp) != 2) continue;
int j = begin(mp)->fi;
int k = next(begin(mp))->fi;
if (mp[j] != 2) swap(j, k);
if (!(i < j)) continue;
int color_ik = get_color(i, k);
int color_jk = get_color(j, k);
if (color_jk != -1 and color_ik != color_jk) ans += 1;
}
trc2(ans);
// 次数 4
rep(i, N) {
if (sz(g[i]) != 3) continue;
int j = g[i][0];
int k = g[i][1];
int l = g[i][2];
if (j == k or k == l or l == j) continue;
if (i != min({int(i), j, k, l})) continue;
vi c(4);
int ok = 1;
#define add(s, t, u, v) \
{ \
int col = get_color(s, t); \
if (col == -1) { \
ok = 0; \
} else if (col == 1) { \
c[u]++, c[v]++; \
} \
}
add(i, j, 0, 1);
add(i, k, 0, 2);
add(i, l, 0, 3);
add(j, k, 1, 2);
add(j, l, 1, 3);
add(k, l, 2, 3);
if (ok and Sum(c) == 6 and Min(c) > 0 and Max(c) < 3) ans += 1;
}
// 頂点数 4 , その 2
rep(i, N) {
if (sz(g[i]) != 3) continue;
map<int, int> mp;
each(e, g[i]) mp[e]++;
if (sz(mp) != 2) continue;
int j = begin(mp)->fi;
int k = next(begin(mp))->fi;
if (mp[j] != 2) swap(j, k);
if (!(i < j)) continue;
if (sz(g[j]) != 3) continue;
int l = -1;
each(e, g[j]) if (e != i) l = e;
if (st.count({k, l}) == 0) continue;
if (!(i < min(k, l))) continue;
int color_ik = get_color(i, k);
int color_jl = get_color(j, l);
if (color_ik != color_jl) ans += 1;
}
out(ans);
}
void Nyaan::solve() {
int t = 1;
// in(t);
while (t--) q();
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 4 1 2 0 1 3 1 2 3 0 2 3 1
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
4 6 1 2 0 2 3 0 3 4 0 1 4 1 2 4 1 1 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
20 28 9 6 1 9 6 0 3 8 0 8 4 0 3 8 1 3 4 1 2 13 0 13 1 0 19 1 0 2 1 1 2 19 1 13 19 1 14 15 1 14 15 0 7 12 0 12 17 0 20 17 0 7 17 1 7 20 1 12 20 1 16 18 0 18 10 0 5 10 0 16 10 1 16 5 1 18 5 1 4 6 0 9 11 0
output:
27
result:
ok 1 number(s): "27"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
100 150 93 23 0 23 81 0 76 81 0 93 81 1 93 76 1 23 76 1 100 65 0 65 56 0 19 56 0 100 56 1 100 19 1 65 19 1 2 98 0 2 98 1 26 63 0 63 90 0 26 63 1 26 90 1 6 11 0 11 67 0 6 11 1 6 67 1 37 89 0 89 64 0 25 64 0 37 64 1 37 25 1 89 25 1 84 10 0 10 29 0 75 29 0 84 29 1 84 75 1 10 75 1 7 70 1 7 70 0 28 92 0 ...
output:
141
result:
ok 1 number(s): "141"
Test #5:
score: 0
Accepted
time: 54ms
memory: 12836kb
input:
100000 133680 36843 86625 0 86625 63051 0 35524 63051 0 36843 63051 1 36843 35524 1 86625 35524 1 55797 82715 0 55797 82715 1 70147 35104 0 35104 91732 0 70147 35104 1 70147 91732 1 94917 70395 0 70395 68250 0 24100 68250 0 94917 68250 1 94917 24100 1 70395 24100 1 83033 18450 1 83033 18450 0 34462 ...
output:
144604
result:
ok 1 number(s): "144604"
Test #6:
score: 0
Accepted
time: 51ms
memory: 12836kb
input:
100000 133388 86620 74346 0 74346 19047 0 54911 19047 0 86620 19047 1 86620 54911 1 74346 54911 1 23715 93094 0 93094 91208 0 63189 91208 0 23715 91208 1 23715 63189 1 93094 63189 1 99337 41426 1 99337 41426 0 83742 45546 0 45546 73862 0 83742 45546 1 83742 73862 1 85256 2812 0 2812 59368 0 85918 59...
output:
144348
result:
ok 1 number(s): "144348"
Test #7:
score: 0
Accepted
time: 64ms
memory: 14144kb
input:
100000 150000 86541 24385 0 24385 75745 0 52353 75745 0 86541 75745 1 86541 52353 1 24385 52353 1 89075 78015 0 89075 78015 1 52519 74846 0 74846 12045 0 73265 12045 0 52519 12045 1 52519 73265 1 74846 73265 1 17884 63159 0 63159 47308 0 56073 47308 0 17884 47308 1 17884 56073 1 63159 56073 1 72134 ...
output:
144639
result:
ok 1 number(s): "144639"
Test #8:
score: 0
Accepted
time: 62ms
memory: 14348kb
input:
100000 150000 91951 68612 1 91951 68612 0 18361 92673 0 92673 52678 0 86520 52678 0 18361 52678 1 18361 86520 1 92673 86520 1 58779 2421 0 58779 2421 1 66622 6461 0 6461 96943 0 66622 6461 1 66622 96943 1 27201 480 1 27201 480 0 19082 3895 0 3895 17796 0 3117 17796 0 19082 17796 1 19082 3117 1 3895 ...
output:
144471
result:
ok 1 number(s): "144471"
Test #9:
score: 0
Accepted
time: 70ms
memory: 14332kb
input:
100000 150000 43756 3552 0 3552 90269 0 43756 3552 1 43756 90269 1 11104 36935 1 11104 36935 0 11648 5480 0 5480 45320 0 11648 5480 1 11648 45320 1 19216 85746 0 19216 85746 1 68825 11173 0 11173 43155 0 68825 11173 1 68825 43155 1 27349 75259 0 27349 75259 1 1704 24478 0 24478 5980 0 1704 24478 1 1...
output:
144217
result:
ok 1 number(s): "144217"
Test #10:
score: 0
Accepted
time: 67ms
memory: 14168kb
input:
99999 149998 51151 43399 0 51151 43399 1 45978 28343 0 28343 9008 0 85724 9008 0 45978 9008 1 45978 85724 1 28343 85724 1 79446 12915 0 12915 65925 0 28869 65925 0 79446 65925 1 79446 28869 1 12915 28869 1 82642 95556 0 95556 68817 0 68334 68817 0 82642 68817 1 82642 68334 1 95556 68334 1 61212 7638...
output:
144219
result:
ok 1 number(s): "144219"
Test #11:
score: 0
Accepted
time: 62ms
memory: 14144kb
input:
100000 149999 26736 28785 0 28785 37945 0 26736 28785 1 26736 37945 1 1240 74368 0 74368 45022 0 1240 74368 1 1240 45022 1 40673 1276 0 1276 56395 0 40673 1276 1 40673 56395 1 35181 63341 0 63341 35131 0 60120 35131 0 35181 35131 1 35181 60120 1 63341 60120 1 99363 36973 0 99363 36973 1 85717 77683 ...
output:
144380
result:
ok 1 number(s): "144380"
Test #12:
score: 0
Accepted
time: 62ms
memory: 14172kb
input:
100000 150000 63695 11044 0 11044 34978 0 56531 34978 0 63695 34978 1 63695 56531 1 11044 56531 1 72139 3715 0 3715 21024 0 96696 21024 0 72139 21024 1 72139 96696 1 3715 96696 1 54670 49014 0 54670 49014 1 7670 61055 0 61055 38409 0 7670 61055 1 7670 38409 1 83399 50676 0 50676 98893 0 60069 98893 ...
output:
144559
result:
ok 1 number(s): "144559"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #14:
score: 0
Accepted
time: 2ms
memory: 5400kb
input:
100000 0
output:
100000
result:
ok 1 number(s): "100000"
Test #15:
score: 0
Accepted
time: 54ms
memory: 11888kb
input:
100000 150000 95066 31960 0 31960 89758 0 10935 89758 0 95066 89758 1 95066 10935 1 31960 10935 1 48016 97823 0 97823 10871 0 23454 10871 0 48016 10871 1 48016 23454 1 97823 23454 1 73749 35525 0 35525 54232 0 42182 54232 0 73749 54232 1 73749 42182 1 35525 42182 1 75405 71341 0 71341 70032 0 3284 7...
output:
125000
result:
ok 1 number(s): "125000"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
4 6 1 2 0 1 2 1 1 3 0 2 4 1 3 4 0 3 4 1
output:
7
result:
ok 1 number(s): "7"
Test #17:
score: 0
Accepted
time: 36ms
memory: 10896kb
input:
99998 115940 40840 40839 0 28249 28248 0 24785 24783 0 36536 36534 1 71904 71901 1 62023 62021 0 34737 34740 1 18430 18434 0 27506 27505 1 4665 4664 1 36578 36577 1 99311 99314 1 43484 43482 0 26457 26459 1 99698 99695 0 10170 10172 1 98176 98179 1 47786 47785 1 56529 56531 1 86896 86895 1 78204 782...
output:
104913
result:
ok 1 number(s): "104913"
Test #18:
score: 0
Accepted
time: 48ms
memory: 11400kb
input:
99996 126880 57665 57662 0 73031 73028 0 78744 78741 1 36913 36914 0 88139 88138 1 89276 89278 0 66433 66436 1 91069 91070 0 63929 63930 0 89625 89627 0 56400 56399 1 69226 69223 1 88433 88432 1 43807 43810 0 37146 37145 0 43789 43792 1 68123 68124 1 17957 17954 1 82804 82805 0 59808 59804 1 73840 7...
output:
103597
result:
ok 1 number(s): "103597"
Test #19:
score: 0
Accepted
time: 43ms
memory: 11588kb
input:
99996 128661 40089 40092 1 43861 43862 1 75629 75628 0 19597 19598 0 15151 15154 0 95642 95641 0 80320 80317 1 57255 57254 0 35316 35314 0 44675 44676 1 38847 38850 0 50886 50883 1 7617 7615 0 52310 52311 0 71474 71478 1 60036 60035 1 12009 12012 1 72347 72348 1 80343 80345 0 58804 58806 1 11386 113...
output:
103531
result:
ok 1 number(s): "103531"
Test #20:
score: 0
Accepted
time: 42ms
memory: 10992kb
input:
85086 109171 68997 68998 1 24077 24074 0 81830 81829 0 6102 6100 0 16851 16850 0 44103 44101 0 35639 35637 0 46162 46161 1 70373 70372 1 2625 2624 0 50990 50989 0 52220 52219 1 3452 3453 0 21915 21916 0 19561 19564 1 2616 2615 1 59039 59040 1 72589 72590 1 40147 40148 0 83359 83360 1 4274 4275 1 736...
output:
96534
result:
ok 1 number(s): "96534"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
6 9 1 2 0 1 2 1 1 3 0 2 3 1 3 4 0 4 5 0 4 6 1 5 6 0 5 6 1
output:
10
result:
ok 1 number(s): "10"
Test #22:
score: 0
Accepted
time: 45ms
memory: 10972kb
input:
99998 115940 91307 35051 0 41850 19274 0 35587 78894 0 26695 91651 1 79179 482 1 26680 7283 0 51999 18100 1 97541 51977 0 31565 24059 1 48770 33590 1 79885 37272 1 16578 79254 1 23825 66223 0 51722 3968 1 30481 33229 0 86577 14556 1 63261 87530 1 17567 19857 1 48438 12110 1 68610 47458 1 88373 92315...
output:
104913
result:
ok 1 number(s): "104913"
Test #23:
score: 0
Accepted
time: 48ms
memory: 11356kb
input:
99996 126880 31926 32431 0 89751 77638 0 81312 90949 1 9164 78061 0 79960 37357 1 15044 53165 0 46804 58840 1 96661 32396 0 93436 39774 0 81650 97489 0 28285 25380 1 51642 75847 1 38686 99309 1 65477 46389 0 17012 64436 0 39535 20467 1 55466 34797 1 56580 52438 1 88447 46598 0 94878 81598 1 36359 71...
output:
103597
result:
ok 1 number(s): "103597"
Test #24:
score: 0
Accepted
time: 46ms
memory: 11520kb
input:
99996 128661 68631 18634 1 39185 98747 1 93688 3993 0 63831 49896 0 88466 11249 0 76247 13150 0 44166 89827 1 14706 98796 0 55609 32463 0 96040 11481 1 15800 28436 0 35644 61568 1 90823 7941 0 16497 32517 0 70520 2507 1 36824 37963 1 43899 12185 1 16439 35062 1 22697 5663 0 22986 20940 1 93694 62377...
output:
103531
result:
ok 1 number(s): "103531"
Test #25:
score: 0
Accepted
time: 41ms
memory: 11160kb
input:
85086 109171 54967 52668 1 64243 48915 0 78737 27043 0 69272 84477 0 11191 72192 0 56490 36228 0 52083 25417 0 58946 51014 1 57855 26735 1 83625 46445 0 72878 43133 0 77230 69968 1 7791 38318 0 14928 27213 0 5215 50302 1 75864 25928 1 11582 54867 1 53793 83950 1 70191 16278 0 69499 3665 1 45931 3663...
output:
96534
result:
ok 1 number(s): "96534"
Test #26:
score: 0
Accepted
time: 85ms
memory: 16808kb
input:
100000 150000 99933 55358 0 90416 2554 0 64997 12630 0 43499 35304 0 43164 38359 0 82333 47941 0 15092 76350 1 6401 82373 0 90467 57736 1 72290 58218 0 64844 79192 0 71055 40232 1 54743 65698 0 19204 38062 1 1490 24882 0 18848 1970 1 18829 25405 0 93396 54676 1 5241 60149 0 26699 39910 1 70898 82827...
output:
150000
result:
ok 1 number(s): "150000"
Test #27:
score: 0
Accepted
time: 65ms
memory: 13848kb
input:
100000 130000 15237 21286 1 60817 70086 1 62915 43855 1 23616 97040 1 54175 84281 1 22498 80217 1 58904 98534 0 88649 79847 0 46299 28927 1 90160 25868 1 59368 62900 1 93860 42461 1 2630 7547 1 54787 84637 1 6577 95373 1 62108 8000 1 14358 53523 1 85474 77621 1 68271 30113 1 26333 71197 1 78110 6040...
output:
130000
result:
ok 1 number(s): "130000"
Test #28:
score: 0
Accepted
time: 41ms
memory: 10484kb
input:
65534 98300 42421 54323 0 45888 19783 0 11682 46414 0 41620 27016 0 62650 43400 1 24787 17246 0 38437 37760 0 51438 27810 0 5194 36179 0 42153 44739 0 38012 47581 0 64561 26437 0 30761 19033 0 29631 18563 0 10689 6913 0 9438 48319 0 18569 39847 0 21454 526 0 59916 36345 0 2577 7295 0 22843 14281 0 4...
output:
81918
result:
ok 1 number(s): "81918"
Test #29:
score: 0
Accepted
time: 46ms
memory: 10552kb
input:
65534 98300 44683 25158 1 35394 27103 0 11618 63123 1 26627 62829 1 63124 18531 1 38195 27395 0 30743 3378 1 52310 58855 0 59905 3467 0 60227 44700 0 4466 13169 0 11289 35510 1 45259 23426 1 55348 47991 1 48231 26070 1 48525 16062 1 57931 14114 1 27522 12180 0 12757 20313 1 42080 63292 0 26595 51845...
output:
81918
result:
ok 1 number(s): "81918"
Test #30:
score: 0
Accepted
time: 44ms
memory: 10608kb
input:
65534 98300 13270 32154 0 55961 42311 1 28791 53182 1 59289 50275 1 8038 50111 1 26166 35350 1 11126 60403 1 39908 858 0 59214 30194 1 35679 36357 1 3720 42580 1 24721 42253 1 39094 30603 1 6697 51066 0 3419 63371 1 64362 40934 1 51257 14082 1 63044 59478 1 20968 167 1 30514 42744 1 41849 32144 1 16...
output:
81918
result:
ok 1 number(s): "81918"
Test #31:
score: 0
Accepted
time: 48ms
memory: 11292kb
input:
100000 98302 61966 27142 0 53993 68970 0 34298 58099 1 63874 66725 0 14229 34649 0 2188 81478 0 11724 47884 0 19350 71019 0 61938 51579 0 35352 84486 0 84906 82998 0 14543 39824 0 48746 90624 0 40191 40994 1 47705 23039 0 62784 79792 0 15245 88212 0 92737 95500 0 94811 43930 1 69757 74299 0 53560 49...
output:
116384
result:
ok 1 number(s): "116384"
Test #32:
score: 0
Accepted
time: 52ms
memory: 11340kb
input:
100000 98302 63951 83046 0 49356 1318 1 76776 11042 0 10897 51960 0 91740 36201 1 79579 70160 0 48233 7988 1 77589 73526 0 64917 41777 1 25721 24712 1 40519 61024 0 44493 67177 0 33335 24084 0 3709 42347 0 79762 84853 0 19590 61141 0 77360 58976 0 72886 44054 0 26544 51830 0 5866 45365 0 76622 26661...
output:
124574
result:
ok 1 number(s): "124574"
Test #33:
score: 0
Accepted
time: 48ms
memory: 11328kb
input:
100000 98302 88683 65853 1 85733 28420 1 76008 55360 1 49391 24933 1 87657 14404 1 90800 58622 1 75122 69522 1 22879 73168 1 9291 55797 0 50874 91259 1 86132 9922 1 39521 5711 1 75332 50647 1 14679 89034 1 15252 65542 1 26783 18217 1 11499 26206 1 10487 12140 1 69139 5819 1 62356 90026 1 82272 78670...
output:
116384
result:
ok 1 number(s): "116384"
Test #34:
score: 0
Accepted
time: 54ms
memory: 11796kb
input:
96000 144000 69465 78015 0 70940 79248 0 21267 22945 0 42324 69262 0 92079 61298 0 14312 89231 0 76879 64390 0 9515 87921 0 72921 56907 0 77360 7365 0 5845 31109 0 50706 19916 0 29274 5084 0 27393 91084 0 89690 81434 0 81818 17371 0 59817 87334 0 40802 63933 0 34255 67445 0 84919 73480 0 6355 64057 ...
output:
96000
result:
ok 1 number(s): "96000"
Test #35:
score: 0
Accepted
time: 56ms
memory: 12040kb
input:
98000 147000 64116 52839 0 58466 64469 1 68501 33965 1 35430 29683 1 18936 7790 1 11024 87600 0 87090 27191 1 3526 40531 1 8967 64385 0 74728 9321 1 14888 6420 0 27780 41446 0 56978 5452 0 13425 79329 1 87611 32959 0 3067 17931 0 22989 82933 1 24468 5242 0 47124 59392 1 79914 93411 1 87124 90315 1 7...
output:
98000
result:
ok 1 number(s): "98000"
Test #36:
score: 0
Accepted
time: 49ms
memory: 12056kb
input:
100000 150000 56602 2395 1 82739 49727 1 27928 35973 1 98253 71027 1 35442 98024 1 18060 72579 1 86277 73382 1 47014 51013 1 65310 17335 1 54892 30774 1 77960 822 1 47490 41910 1 62706 85890 1 71056 13146 1 34092 33865 1 58748 46635 1 21972 37259 1 51199 31504 1 43608 87941 1 90790 42330 1 50214 189...
output:
100000
result:
ok 1 number(s): "100000"
Test #37:
score: 0
Accepted
time: 56ms
memory: 11876kb
input:
95000 142500 89254 6524 0 87399 92742 0 50117 8349 0 76363 58825 0 52190 83971 0 6795 20007 0 79651 49566 0 10970 79953 0 11980 53524 0 7467 38087 0 32096 9083 0 17827 38927 0 79988 23057 0 17001 32129 0 56030 42010 0 77569 59418 0 70155 41087 0 27648 77230 0 21167 61067 0 56132 86455 0 80647 19119 ...
output:
95000
result:
ok 1 number(s): "95000"
Test #38:
score: 0
Accepted
time: 57ms
memory: 11820kb
input:
97000 145500 94330 53090 1 74854 79436 0 31002 6670 1 20802 11748 0 23526 78897 0 2600 84830 0 19572 95411 1 87783 55713 0 20454 22602 1 30751 12787 0 67094 60165 0 9477 19434 1 91443 58645 0 49984 1623 0 44709 41427 0 1043 24331 1 79185 42581 0 25102 27915 0 67200 90145 1 25416 40396 1 35961 3087 0...
output:
97000
result:
ok 1 number(s): "97000"
Test #39:
score: 0
Accepted
time: 59ms
memory: 12040kb
input:
99000 148500 63457 58943 1 22274 81761 1 72574 63452 1 67950 79564 1 42979 37610 1 30695 97830 1 33234 77173 1 84106 7156 1 40075 39589 1 41001 66646 1 68993 48814 1 19560 49612 1 80409 70249 1 5995 75043 1 78335 53789 1 87696 94760 1 32934 22366 1 64938 22623 1 49846 19013 1 96854 6968 1 6539 63262...
output:
99000
result:
ok 1 number(s): "99000"
Extra Test:
score: 0
Extra Test Passed