QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311197 | #4781. 完美的集合 | hos_lyric | 100 ✓ | 191ms | 5500kb | C++14 | 14.5kb | 2024-01-22 03:40:33 | 2024-01-22 03:40:34 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned long long M_> struct ModLong {
static constexpr unsigned long long M = M_;
static constexpr long double INV_M = 1.0L / M;
unsigned long long x;
ModLong() : x(0ULL) {}
ModLong(unsigned x_) : x(x_ % M) {}
ModLong(unsigned long long x_) : x(x_ % M) {}
ModLong(int x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModLong(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModLong &operator+=(const ModLong &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModLong &operator-=(const ModLong &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModLong &operator*=(const ModLong &a) {
// https://github.com/kth-competitive-programming/kactl/blob/main/doc/modmul-proof.pdf
// This works at least for M < 2^62, assuming the usual 80-bit long double.
const long long y = x * a.x - M * static_cast<unsigned long long>(INV_M * x * a.x);
x = (y < 0LL) ? (y + M) : (y >= static_cast<long long>(M)) ? (y - M) : y;
return *this;
}
ModLong &operator/=(const ModLong &a) { return (*this *= a.inv()); }
ModLong pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModLong a = *this, b = 1ULL; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModLong inv() const {
unsigned long long a = M, b = x; long long y = 0, z = 1;
for (; b; ) { const unsigned long long q = a / b; const unsigned long long c = a - q * b; a = b; b = c; const long long w = y - static_cast<long long>(q) * z; y = z; z = w; }
assert(a == 1ULL); return ModLong(y);
}
ModLong operator+() const { return *this; }
ModLong operator-() const { ModLong a; a.x = x ? (M - x) : 0ULL; return a; }
ModLong operator+(const ModLong &a) const { return (ModLong(*this) += a); }
ModLong operator-(const ModLong &a) const { return (ModLong(*this) -= a); }
ModLong operator*(const ModLong &a) const { return (ModLong(*this) *= a); }
ModLong operator/(const ModLong &a) const { return (ModLong(*this) /= a); }
template <class T> friend ModLong operator+(T a, const ModLong &b) { return (ModLong(a) += b); }
template <class T> friend ModLong operator-(T a, const ModLong &b) { return (ModLong(a) -= b); }
template <class T> friend ModLong operator*(T a, const ModLong &b) { return (ModLong(a) *= b); }
template <class T> friend ModLong operator/(T a, const ModLong &b) { return (ModLong(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModLong &a) const { return (x == a.x); }
bool operator!=(const ModLong &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModLong &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
using ModInt = ModLong<11920928955078125>;
struct BinomPE {
static constexpr int p = 5;
static constexpr int e = 23;
static constexpr unsigned long long M = 11920928955078125;
ModInt mod(int x_) const {
return x_;
}
ModInt mod(long long x_) const {
return x_;
}
ModInt add(ModInt a, ModInt b) const {
return a + b;
}
ModInt mul(ModInt a, ModInt b) const {
return a * b;
}
ModInt pow(ModInt a, long long e_) const {
return a.pow(e_);
}
ModInt inv(ModInt a) const {
return a.inv();
}
// pp[i] = p^i
vector<unsigned long long> pp;
// period mod p^e of (-1 mod p)
unsigned long long period;
// s1[n][k] = |s(n+1, k+1)| (in particular, s1[p-1][0] = (p-1)!)
vector<vector<ModInt>> s1;
// fs[u] = \prod[0<=i<u] range(i, p-1): poly in u of deg=2e-2
int deg;
vector<ModInt> fs;
// valFac[i] = v_p(i!), invFac[i] = (i! / p^(v_p(i!)))^-1
vector<int> valFac;
vector<ModInt> invFac;
BinomPE() {
assert(p >= 2); assert(e >= 1);
pp.resize(e + 1);
pp[0] = 1;
for (int i = 1; i <= e; ++i) pp[i] = pp[i - 1] * p;
// setM(pp[e]);
period = ((p == 2 && e >= 3) ? 1 : 2) * pp[e - 1];
s1.assign(p, vector<ModInt>(min(p, e), ModInt{0U}));
s1[0][0] = ModInt{1U};
for (int n = 1; n < p; ++n) {
s1[n][0] = mul(mod(n), s1[n - 1][0]);
for (int k = 1; k < min(p, e); ++k) s1[n][k] = add(s1[n - 1][k - 1], mul(mod(n), s1[n - 1][k]));
}
const ModInt invFac1 = inv(s1[p - 1][0]);
deg = 2 * e - 2;
fs.resize(deg + 1);
fs[0] = ModInt{1U};
for (int u = 0; u < deg; ++u) fs[u + 1] = mul(fs[u], mul(invFac1, range(u, p - 1)));
valFac.resize(deg + 1);
invFac.resize(deg + 1);
valFac[0] = 0;
invFac[0] = ModInt{1U};
ModInt prod{1U};
for (int i = 1; i <= deg; ++i) {
int ii = i, val = 0;
for (; ii % p == 0; ii /= p, ++val) {}
valFac[i] = valFac[i - 1] + val;
prod = mul(prod, invFac[i - 1] = mod(ii));
}
invFac[deg] = inv(prod);
for (int i = deg; i >= 1; --i) invFac[i - 1] = mul(invFac[i - 1], invFac[i]);
}
// v_p(n!)
long long valuationFac(long long n) const {
long long ret = 0;
for (; n /= p; ret += n) {}
return ret;
}
// (u p + 1) ... (u p + v)
ModInt range(long long u, int v) const {
const ModInt up = mod(static_cast<long long>(u) * p);
ModInt ret{0U};
for (int k = min(p, e); --k >= 0; ) ret = add(mul(ret, up), s1[v][k]);
return ret;
}
// (\prod[1<=i<=up+v, p!|i] i) / (p-1)!^u
ModInt facSkipped(long long u, int v) const {
const ModInt tail = range(u, v);
if (u <= deg) return mul(fs[u], tail);
vector<pair<int, ModInt>> works(deg + 1);
vector<int> valSuf(deg + 2);
vector<ModInt> prodSuf(deg + 2);
valSuf[deg + 1] = 0;
prodSuf[deg + 1] = ModInt{1U};
for (int i = deg; i >= 0; --i) {
long long uu = u - i;
int val = 0;
for (; uu % p == 0; uu /= p) ++val;
works[i] = make_pair(val, mod(uu));
valSuf[i] = val + valSuf[i + 1];
prodSuf[i] = mul(works[i].second, prodSuf[i + 1]);
}
int valPre = 0;
ModInt prodPre = ModInt{1U};
ModInt sum = ModInt{0U};
for (int i = 0; i <= deg; ++i) {
// (u-0)...(u-(i-1))(u-(i+1))...(u-deg) / (i-0)...(i-(i-1))(i-(i+1))...(i-deg)
const int val = valPre + valSuf[i + 1] - valFac[i] - valFac[deg - i];
if (val < e) {
sum = add(sum, mul(mul(
mul(ModInt{pp[val]}, mul(prodPre, prodSuf[i + 1])),
mul(invFac[i], mul(invFac[deg - i], mod(((deg - i) & 1) ? -1 : +1)))
), fs[i]));
}
valPre += works[i].first;
prodPre = mul(prodPre, works[i].second);
}
return mul(sum, tail);
}
// n! / p^(v_p(n!))
ModInt facP(long long n) const {
long long sum = 0;
ModInt prod{1U};
for (; n; ) {
const long long q = n / p, v = n % p;
const long long u = q % period;
sum += u;
prod = mul(prod, facSkipped(u, v));
n = q;
}
return mul(pow(s1[p - 1][0], sum % period), prod);
}
// binom(n, k)
ModInt operator()(long long n, long long k) const {
if (n < 0) {
if (k >= 0) {
return mul(mod((k & 1) ? -1 : +1), (*this)(-n + k - 1, k));
} else if (n - k >= 0) {
return mul(mod(((n - k) & 1) ? -1 : +1), (*this)(-k - 1, n - k));
} else {
return ModInt{0U};
}
} else {
if (0 <= k && k <= n) {
const long long val = valuationFac(n) - valuationFac(k) - valuationFac(n - k);
if (val >= e) return ModInt{0U};
return mul(ModInt{pp[val]}, mul(facP(n), inv(mul(facP(k), facP(n - k)))));
} else {
return ModInt{0U};
}
}
}
} binom;
constexpr Int INFLL = 1001001001001001001LL;
int N, M, K;
Int L;
vector<int> W;
vector<Int> V;
vector<int> A, B, C;
vector<vector<int>> G;
namespace brute {
ModInt run() {
vector<int> adj(N, 0);
for (int i = 0; i < N - 1; ++i) {
adj[A[i]] |= 1 << B[i];
adj[B[i]] |= 1 << A[i];
}
vector<int> WSum(1 << N, 0);
vector<Int> VSum(1 << N, 0);
vector<int> es(1 << N, 0);
for (int u = 0; u < N; ++u) for (int p = 0; p < 1 << u; ++p) {
WSum[p | 1 << u] = WSum[p] + W[u];
VSum[p | 1 << u] = VSum[p] + V[u];
es[p | 1 << u] = es[p] + __builtin_popcount(p & adj[u]);
}
Int maxV = -1;
vector<int> ps;
for (int p = 0; p < 1 << N; ++p) if (WSum[p] <= M && es[p] == __builtin_popcount(p) - 1) {
if (chmax(maxV, VSum[p])) ps.clear();
if (maxV == VSum[p]) ps.push_back(p);
}
cerr<<"ps = "<<ps<<endl;
vector<vector<int>> dist(N, vector<int>(N, 1001001001));
for (int u = 0; u < N; ++u) dist[u][u] = 0;
for (int i = 0; i < N - 1; ++i) dist[A[i]][B[i]] = dist[B[i]][A[i]] = C[i];
for (int w = 0; w < N; ++w) for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) chmin(dist[u][v], dist[u][w] + dist[w][v]);
ModInt ans = 0;
for (int u = 0; u < N; ++u) {
Int way = 0;
for (const int p : ps) if (p >> u & 1) {
bool ok = true;
for (int v = 0; v < N; ++v) if (p >> v & 1) {
ok = ok && (dist[u][v] * V[v] <= L);
}
if (ok) ++way;
}
cerr<<COLOR("91")<<u<<": "<<way<<COLOR()<<endl;
ans += binom(way, K);
}
for (int i = 0; i < N - 1; ++i) {
Int way = 0;
for (const int p : ps) if ((p >> A[i] & 1) && (p >> B[i] & 1)) {
bool ok = true;
for (int v = 0; v < N; ++v) if (p >> v & 1) {
ok = ok && (max(dist[A[i]][v], dist[B[i]][v]) * V[v] <= L);
}
if (ok) ++way;
}
cerr<<COLOR("94")<<A[i]<<" "<<B[i]<<": "<<way<<COLOR()<<endl;
ans -= binom(way, K);
}
return ans;
}
} // brute
namespace sub3 {
ModInt run() {
Int maxV = -1;
if (M == 1) {
vector<int> us;
for (int u = 0; u < N; ++u) {
if (chmax(maxV, V[u])) us.clear();
if (maxV == V[u]) us.push_back(u);
}
return (int)us.size() * binom(1, K);
}
vector<int> is;
for (int i = 0; i < N - 1; ++i) {
if (chmax(maxV, V[A[i]] + V[B[i]])) is.clear();
if (maxV == V[A[i]] + V[B[i]]) is.push_back(i);
}
cerr<<"is = "<<is<<endl;
ModInt ans = 0;
for (int u = 0; u < N; ++u) {
Int way = 0;
for (const int i : is) if (A[i] == u || B[i] == u) {
const int v = A[i] ^ B[i] ^ u;
if (C[i] * V[v] <= L) ++way;
}
cerr<<COLOR("91")<<u<<": "<<way<<COLOR()<<endl;
ans += binom(way, K);
}
for (const int i : is) {
Int way = 0;
if (C[i] * max(V[A[i]], V[B[i]]) <= L) ++way;
cerr<<COLOR("94")<<A[i]<<" "<<B[i]<<": "<<way<<COLOR()<<endl;
ans -= binom(way, K);
}
return ans;
}
} // brute
namespace fast {
// (max value, way)
using Pair = pair<Int, Int>;
constexpr Pair ZERO(-INFLL, 0);
Pair operator+(const Pair &a, const Pair &b) {
if (a.first > b.first) return a;
if (a.first < b.first) return b;
return Pair(a.first, a.second + b.second);
}
vector<Pair> dfs(int phase, int u, int p, int d, vector<Pair> fs) {
if (phase == 1 && d * V[u] > L) return vector<Pair>(M + 1, ZERO);
for (int m = M; m >= 0; --m) {
if (m >= W[u]) {
(fs[m] = fs[m - W[u]]).first += V[u];
} else {
fs[m] = ZERO;
}
}
for (const int i : G[u]) {
const int v = A[i] ^ B[i] ^ u;
if (p != v) {
const auto res = dfs(phase, v, u, d + C[i], fs);
for (int m = 0; m <= M; ++m) fs[m] = fs[m] + res[m];
}
}
return fs;
}
ModInt run() {
vector<Pair> ini(M + 1, ZERO);
ini[0] = Pair(0, 1);
Int maxV = -INFLL;
for (int u = 0; u < N; ++u) {
const auto res = dfs(0, u, -1, 0, ini);
// cerr<<u<<": "<<res<<endl;
for (int m = 0; m <= M; ++m) {
if (m) chmax(maxV, res[m].first);
}
}
cerr<<"maxV = "<<maxV<<endl;
ModInt ans = 0;
for (int u = 0; u < N; ++u) {
const auto res = dfs(1, u, -1, 0, ini);
Int way = 0;
for (int m = 0; m <= M; ++m) if (m) if (maxV == res[m].first) way += res[m].second;
cerr<<COLOR("91")<<u<<": "<<way<<" "<<binom(way,K)<<COLOR()<<endl;
ans += binom(way, K);
}
for (int i = 0; i < N - 1; ++i) {
const auto resA = dfs(1, A[i], B[i], C[i], ini);
const auto resB = dfs(1, B[i], A[i], C[i], ini);
// cerr<<A[i]<<" "<<B[i]<<": "<<resA<<" "<<resB<<endl;
Int way = 0;
{
Pair sum = ZERO;
for (int m = M; m >= 0; --m) {
if (M - m) sum = sum + resA[M - m];
if (m) if (maxV == sum.first + resB[m].first) {
way += sum.second * resB[m].second;
}
}
}
cerr<<COLOR("94")<<A[i]<<" "<<B[i]<<": "<<way<<" "<<binom(way,K)<<COLOR()<<endl;
ans -= binom(way, K);
}
return ans;
}
} // fast
int main() {
for (; ~scanf("%d%d%d%lld", &N, &M, &K, &L); ) {
W.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%d", &W[u]);
chmin(W[u], M + 1);
}
V.resize(N);
for (int u = 0; u < N; ++u) {
scanf("%lld", &V[u]);
}
A.resize(N - 1);
B.resize(N - 1);
C.resize(N - 1);
for (int i = 0; i < N - 1; ++i) {
scanf("%d%d%d", &A[i], &B[i], &C[i]);
--A[i];
--B[i];
}
G.assign(N, {});
for (int i = 0; i < N - 1; ++i) {
G[A[i]].push_back(i);
G[B[i]].push_back(i);
}
ModInt ans = 0;
ans = fast::run();
printf("%llu\n", ans.x);
#ifdef LOCAL
if(N<=20){
const ModInt brt=brute::run();
cerr<<"brt = "<<brt<<endl;
assert(brt==ans);
}
#endif
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 13
Accepted
Test #1:
score: 13
Accepted
time: 1ms
memory: 3788kb
input:
16 109 1 4025082 46 68 46 1 46 67 111 1 156 1 45 45 1 45 45 45 8525 12789 8526 0 8526 12788 954 0 6 0 8525 8526 0 8525 8526 8526 1 2 290 1 3 188 1 4 420 1 5 6 2 6 29 1 7 643 1 8 461 4 9 468 1 10 228 5 11 428 2 12 71 4 13 290 1 14 957 2 15 955 4 16 549
output:
25
result:
ok 1 number(s): "25"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
17 144 2 3550388 2 1 3 1 60 88 2 2 59 60 88 2 1 2 1 89 60 0 0 0 0 6962 10443 0 0 6962 6962 10442 0 0 0 0 10443 6962 1 2 25 1 3 715 1 4 337 1 5 267 1 6 146 1 7 634 5 8 208 1 9 562 1 10 134 2 11 984 2 12 891 3 13 330 5 14 854 3 15 961 3 16 679 5 17 388
output:
116886
result:
ok 1 number(s): "116886"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
17 131 6 4918336 68 67 1 46 134 45 46 1 45 1 45 67 1 1 1 1 45 10569 10568 0 7046 9079 7046 7046 0 7046 0 7045 10569 0 0 0 0 7045 1 2 357 1 3 219 2 4 379 1 5 683 1 6 772 1 7 125 1 8 297 1 9 912 3 10 438 5 11 319 2 12 850 1 13 280 2 14 925 1 15 20 1 16 412 1 17 718
output:
12271512
result:
ok 1 number(s): "12271512"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
16 51 4 497 7 2 6 8 9 1 5 9 4 6 8 7 4 9 6 3 40 16 48 56 72 8 40 56 16 32 48 56 32 56 32 8 1 2 5 2 3 2 1 4 3 1 5 3 4 6 5 3 7 3 2 8 3 3 9 5 1 10 1 5 11 4 5 12 1 6 13 4 7 14 5 3 15 5 1 16 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
15 11 1 214 2 2 1 2 2 1 3 2 3 2 3 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 2 3 2 3 5 1 4 2 2 5 5 2 6 4 2 7 1 2 8 4 1 9 1 5 10 1 1 11 2 1 12 1 1 13 4 1 14 2 2 15 3
output:
95
result:
ok 1 number(s): "95"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
17 15 4 609 1 2 3 1 2 2 3 2 2 1 3 3 3 2 3 2 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 1 2 4 1 3 1 3 4 1 1 5 2 1 6 1 6 7 2 1 8 2 2 9 4 6 10 5 1 11 5 7 12 5 3 13 4 9 14 2 4 15 3 1 16 5 8 17 3
output:
35
result:
ok 1 number(s): "35"
Test #7:
score: 0
Accepted
time: 1ms
memory: 4036kb
input:
17 46 3 343 5 8 6 4 8 2 7 3 3 5 3 3 8 4 6 8 2 28 49 35 21 49 14 49 21 14 28 7 21 49 28 28 42 14 1 2 1 1 3 5 2 4 4 1 5 2 5 6 3 3 7 2 2 8 1 1 9 3 4 10 4 1 11 1 9 12 1 2 13 4 9 14 3 2 15 1 10 16 3 1 17 4
output:
56
result:
ok 1 number(s): "56"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
17 61 2 160 3 8 4 6 8 3 4 1 10 7 10 4 11 10 3 2 5 3 22 12 12 22 9 12 3 32 16 32 12 28 28 3 6 12 1 2 3 1 3 3 1 4 3 1 5 3 2 6 5 2 7 1 1 8 4 1 9 2 1 10 1 8 11 5 2 12 4 1 13 5 5 14 2 2 15 5 9 16 1 4 17 4
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3824kb
input:
17 131 2 4260513 67 2 45 68 2 2 45 1 111 1 45 111 45 45 1 133 67 9141 0 6094 9141 0 0 6094 0 4805 0 6093 3025 6093 6094 0 8617 9141 1 2 962 1 3 31 2 4 347 1 5 351 2 6 799 1 7 486 1 8 763 2 9 538 1 10 263 6 11 311 1 12 779 1 13 987 1 14 118 3 15 933 3 16 668 3 17 677
output:
4561
result:
ok 1 number(s): "4561"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
16 124 4 3205604 177 1 52 152 1 127 77 2 51 76 2 1 52 1 76 1 6773 0 7470 10266 0 2242 11205 0 7470 11205 0 0 7470 0 11205 0 1 2 800 2 3 684 1 4 961 1 5 190 2 6 653 1 7 834 2 8 378 2 9 985 2 10 158 2 11 380 1 12 304 5 13 419 1 14 818 5 15 56 4 16 466
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 1ms
memory: 4064kb
input:
17 124 7 2772308 2 77 1 2 2 126 2 52 76 51 51 52 1 51 1 51 1 0 8264 0 0 0 3576 0 5510 8265 5510 5510 5510 0 5509 0 5509 0 1 2 714 1 3 913 1 4 884 1 5 821 1 6 145 2 7 749 4 8 645 2 9 79 1 10 945 1 11 130 2 12 817 1 13 311 1 14 808 2 15 351 2 16 278 13 17 430
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
16 124 4 6533568 2 2 1 51 76 1 152 77 51 2 1 2 1 52 76 77 0 0 0 7977 11967 0 5499 11967 7978 0 0 0 0 7978 11967 11967 1 2 691 1 3 957 1 4 858 3 5 318 1 6 3 1 7 155 3 8 888 1 9 32 1 10 434 2 11 609 2 12 591 2 13 784 4 14 87 1 15 558 2 16 168
output:
1088430
result:
ok 1 number(s): "1088430"
Subtask #2:
score: 11
Accepted
Test #13:
score: 11
Accepted
time: 9ms
memory: 3912kb
input:
40 816 1 285 46 124 125 137 90 33 15 73 67 41 134 106 3 163 152 151 14 77 157 82 40 9 151 148 60 60 163 71 40 134 152 145 70 59 26 64 94 38 158 57 2 2 1 1 1 1 3 3 1 1 3 3 1 3 1 3 2 1 3 3 1 1 2 2 3 2 1 2 1 2 2 1 3 3 3 1 1 1 3 3 1 2 20 1 3 26 2 4 14 3 5 25 1 6 17 4 7 49 1 8 37 1 9 50 2 10 52 4 11 55 2...
output:
3
result:
ok 1 number(s): "3"
Test #14:
score: 0
Accepted
time: 6ms
memory: 4100kb
input:
39 617 1 172 60 66 69 46 26 120 82 68 86 29 11 115 56 36 97 89 43 101 92 25 57 45 26 1 111 67 93 84 4 74 36 67 63 60 64 83 104 5 110 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2 2 2 1 2 52 1 3 22 1 4 50 3 5 19 1 6 26 1 7 48 1 8 30 3 9 55 2 10 18 5 11 28 5 12 19 1 13 55 1...
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: 0
Accepted
time: 104ms
memory: 5500kb
input:
59 9134 1 30156516 1838 15 2444 1837 3666 1840 2447 1835 10 3057 9 2444 13 3662 13 1836 3057 2448 3055 12 15 11 8 4271 9 12 11 3055 1835 3057 2446 2449 2446 12 3663 12 2440 8 3666 1837 1837 3057 9 2447 3057 1835 1837 2446 1838 2442 2443 2447 2449 1835 3058 11 4274 3664 2441 13038 0 17384 13037 7589 ...
output:
129
result:
ok 1 number(s): "129"
Test #16:
score: 0
Accepted
time: 80ms
memory: 4224kb
input:
58 8015 1 8074143 2517 2009 1516 2517 9 6 13 3 3517 9 10 9 9 9 2512 11 2510 2012 8 3518 9 8 3520 7 9 3517 6 5 8 9 10 6 10 9 2012 10 2514 9 3017 10 1514 9 7 2513 4 3515 9 3513 8 7 10 11 2512 5 2013 1511 9 9 20765 16611 12458 2031 0 0 0 0 9640 0 0 0 0 0 20765 0 20764 16611 0 7291 0 0 9833 0 0 13633 0 ...
output:
552960
result:
ok 1 number(s): "552960"
Subtask #3:
score: 19
Accepted
Test #17:
score: 19
Accepted
time: 2ms
memory: 4028kb
input:
60 2 14 266401688520 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 712303980 712303980 712303979 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980 712303980...
output:
120
result:
ok 1 number(s): "120"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
56 2 7 534719494983 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 649719921 649719921 649719920 649719921 649719920 649719921 649719921 649719921 649719921 649719921 649719921 649719921 649719921 649719921 649719921 649719921 64971992...
output:
12620256
result:
ok 1 number(s): "12620256"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
59 2 18 362091866924 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 542053693 542053693 542053693 542053693 542053693 542053693 542053693 542053693 542053693 542053693 542053693 542053692 542053693 542053693 542053693 542053693 5...
output:
1037158320
result:
ok 1 number(s): "1037158320"
Subtask #4:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #20:
score: 20
Accepted
time: 8ms
memory: 3880kb
input:
38 824 297026215 792467536225 43 44 43 43 44 43 42 44 44 43 44 41 42 42 42 41 42 41 43 42 43 43 44 42 41 42 44 41 41 42 43 41 44 42 41 41 43 41 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757275 695757...
output:
2981716339453125
result:
ok 1 number(s): "2981716339453125"
Test #21:
score: 0
Accepted
time: 8ms
memory: 3864kb
input:
40 809 403469851 19393977305 41 40 40 41 38 41 39 38 39 39 39 39 40 39 40 40 38 41 40 38 41 40 41 38 39 39 39 39 38 38 39 40 39 39 39 39 39 40 38 39 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 17582935 1758293...
output:
2857142298828125
result:
ok 1 number(s): "2857142298828125"
Test #22:
score: 0
Accepted
time: 9ms
memory: 3876kb
input:
40 1079 13 14770156 91 136 2 137 227 91 91 2 136 1 1 1 316 1 316 1 91 136 91 1 226 271 316 316 1 226 1 1 91 1 226 136 1 226 1 91 1 1 316 91 8551 12827 0 12828 6780 8552 8552 0 12828 0 0 0 11743 0 12592 0 8552 12828 8552 0 1821 6849 15051 128 0 147 0 0 8551 0 2569 12828 0 3421 0 8552 0 0 1479 8552 1 ...
output:
4203807219184050
result:
ok 1 number(s): "4203807219184050"
Test #23:
score: 0
Accepted
time: 10ms
memory: 3924kb
input:
38 1034 8 12979248 92 1 91 1 92 1 136 137 91 2 91 91 137 317 1 1 91 91 1 91 91 316 1 1 1 136 226 1 136 1 136 91 136 226 91 1 136 1 4810 0 4810 0 4810 0 7215 7215 4810 0 4809 4810 7215 3740 0 0 4810 4810 0 4810 4810 7033 0 0 0 7215 1875 0 7215 0 7215 4810 7215 4133 4809 0 7215 0 1 2 762 1 3 364 3 4 7...
output:
7016883917441995
result:
ok 1 number(s): "7016883917441995"
Test #24:
score: 0
Accepted
time: 7ms
memory: 3944kb
input:
38 1079 10 12134760 136 136 1 1 137 136 316 317 91 271 91 136 92 2 1 137 136 136 1 91 137 91 1 91 1 91 136 91 136 1 136 91 91 91 271 1 1 1 8597 8598 0 0 8598 8598 4762 7182 5732 1464 5731 8598 5732 0 0 8598 8598 8598 0 5731 8598 5731 0 5732 0 5732 8598 5732 8598 0 8597 5732 5732 5732 7218 0 0 0 1 2 ...
output:
50061647328900
result:
ok 1 number(s): "50061647328900"
Test #25:
score: 0
Accepted
time: 9ms
memory: 3912kb
input:
39 1034 7 8756596 317 1 1 92 227 271 137 2 1 271 1 1 1 136 1 91 91 91 1 1 1 91 1 1 226 91 91 136 136 91 271 91 91 1 226 1 1 136 91 447 0 0 6868 2502 10058 10301 0 0 2370 0 0 0 10302 0 6868 6867 6868 0 0 0 6868 0 0 342 6867 6868 10302 10302 6867 3528 6868 6868 0 3946 0 0 10302 6867 1 2 173 1 3 386 1 ...
output:
3194876257623260
result:
ok 1 number(s): "3194876257623260"
Test #26:
score: 0
Accepted
time: 3ms
memory: 4176kb
input:
40 692 5 321 129 36 115 89 33 115 82 62 13 102 29 129 61 95 107 66 121 44 73 21 128 40 134 95 65 126 18 94 39 136 81 11 122 117 95 118 92 111 78 51 2 2 2 2 1 2 3 1 3 3 2 1 2 1 2 2 3 1 1 1 2 2 1 3 1 3 3 2 2 2 1 1 1 1 1 3 3 2 2 2 1 2 53 2 3 35 1 4 55 1 5 59 1 6 43 2 7 31 2 8 13 4 9 10 6 10 21 3 11 15 ...
output:
2002
result:
ok 1 number(s): "2002"
Test #27:
score: 0
Accepted
time: 8ms
memory: 3872kb
input:
39 805 6 446 42 152 107 86 86 115 97 120 154 140 52 109 92 104 40 79 26 138 49 94 129 107 143 147 104 69 124 83 102 31 112 76 62 123 143 83 115 25 139 3 2 1 3 1 3 2 3 3 3 2 2 2 2 2 3 3 3 2 3 1 1 2 3 3 3 2 3 3 3 2 2 3 3 3 1 1 3 2 1 2 48 1 3 51 3 4 28 2 5 39 1 6 53 2 7 40 4 8 16 5 9 22 5 10 54 5 11 35...
output:
7
result:
ok 1 number(s): "7"
Subtask #5:
score: 15
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #28:
score: 15
Accepted
time: 148ms
memory: 4428kb
input:
58 7773 3707 498735913284 267 266 265 268 268 267 267 265 266 266 266 265 267 265 267 266 266 268 266 267 269 264 265 267 265 264 265 267 266 265 266 266 264 265 266 267 265 267 265 264 265 265 265 265 267 265 266 265 268 265 268 265 263 267 267 265 265 266 562272732 562272732 562272732 562272732 56...
output:
760088902714635
result:
ok 1 number(s): "760088902714635"
Test #29:
score: 0
Accepted
time: 150ms
memory: 4188kb
input:
58 7895 4910 653150269368 270 270 269 271 270 270 271 269 273 269 271 270 270 269 272 271 272 268 271 269 269 269 269 271 271 268 271 269 271 270 270 270 269 269 270 269 269 270 270 270 270 269 269 270 271 269 269 269 268 269 272 270 270 268 269 271 269 272 679656888 679656888 679656888 679656888 67...
output:
8160378842014935
result:
ok 1 number(s): "8160378842014935"
Test #30:
score: 0
Accepted
time: 120ms
memory: 4180kb
input:
57 7831 2796 279686596890 278 278 278 279 279 277 277 278 277 278 275 278 275 275 276 277 279 274 275 276 277 276 279 277 277 276 277 276 277 276 276 276 276 276 278 277 276 275 279 275 279 279 279 278 280 277 277 277 278 278 277 278 276 278 277 278 278 321478847 321478847 321478847 321478847 321478...
output:
4509998364070125
result:
ok 1 number(s): "4509998364070125"
Test #31:
score: 0
Accepted
time: 187ms
memory: 4600kb
input:
60 8799 6468 13989018 11 11 6 9 2212 7 7 13 10 3309 2208 12 8 9 1658 10 3858 3311 10 10 3310 10 3855 7 2207 2757 7 3863 2762 9 9 11 2210 2207 11 9 12 9 3309 7 13 6 2208 8 7 3858 2756 9 7 7 9 9 2758 3311 1664 13 12 3857 3857 10 0 0 0 0 14756 0 0 0 0 7299 14756 0 0 0 11067 0 12089 324 0 0 5330 0 3166 ...
output:
3868988691264880
result:
ok 1 number(s): "3868988691264880"
Test #32:
score: 0
Accepted
time: 151ms
memory: 4520kb
input:
60 8879 7168 12509148 14 1785 8 2380 1784 9 11 11 1782 9 9 10 8 1787 2377 12 10 13 2969 3562 9 9 4153 9 1786 8 11 2969 14 11 7 9 11 7 1788 1790 3564 2375 12 3562 9 9 2377 2969 13 11 3562 2970 2969 2965 2381 2967 2972 11 6 11 8 4156 1786 9 0 11706 0 15608 11706 0 0 0 11706 0 0 0 0 11706 15608 0 0 0 4...
output:
711105703368750
result:
ok 1 number(s): "711105703368750"
Test #33:
score: 0
Accepted
time: 172ms
memory: 4340kb
input:
56 8699 6609 16065728 10 1747 3491 1746 7 11 9 15 10 4070 3490 12 8 2331 1747 2331 2911 13 2910 17 11 1751 2330 15 3492 1749 9 2910 8 11 3488 10 2913 9 2908 7 13 2911 13 7 1755 11 2330 8 10 3489 9 2909 1751 1753 4072 2912 2909 11 4069 2910 0 11424 9794 11424 0 0 0 0 0 11155 1206 0 0 15231 11424 1523...
output:
1610532740112500
result:
ok 1 number(s): "1610532740112500"
Test #34:
score: 0
Accepted
time: 48ms
memory: 3852kb
input:
60 1000 10000 10000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1...
output:
8133992117154305
result:
ok 1 number(s): "8133992117154305"
Subtask #6:
score: 22
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #35:
score: 22
Accepted
time: 191ms
memory: 4432kb
input:
60 8130 261005878 550649552654 269 270 268 270 270 272 271 267 269 268 269 267 269 269 268 269 268 269 268 269 271 270 268 269 270 268 270 266 270 269 269 269 268 268 269 268 271 271 269 268 268 269 269 266 270 269 270 270 268 269 267 269 269 268 268 269 270 269 268 267 362985862 362985862 362985862...
output:
4776522688750625
result:
ok 1 number(s): "4776522688750625"
Test #36:
score: 0
Accepted
time: 151ms
memory: 4156kb
input:
56 8095 336919779 973340439030 286 286 288 287 288 286 286 287 287 288 287 287 286 286 285 283 286 286 286 287 286 287 289 286 286 288 284 286 284 285 287 287 285 284 286 285 285 284 287 286 287 286 285 288 285 287 289 286 284 287 286 285 286 286 286 285 667586035 667586035 667586035 667586035 66758...
output:
8732248986328125
result:
ok 1 number(s): "8732248986328125"
Test #37:
score: 0
Accepted
time: 164ms
memory: 4440kb
input:
56 8684 169609843 22600968 1748 10 10 11 9 2909 12 2326 1745 9 10 7 11 10 2322 4063 13 10 4062 4064 2904 1750 7 9 12 3483 1750 1747 2909 2324 10 2906 10 10 3483 9 9 2326 1747 7 10 11 7 2330 3487 3484 12 2910 12 14 2904 4067 8 10 10 9 10718 0 0 0 0 17865 0 14292 10718 0 0 0 0 0 14292 5540 0 0 2637 34...
output:
6353419102268750
result:
ok 1 number(s): "6353419102268750"
Test #38:
score: 0
Accepted
time: 152ms
memory: 4468kb
input:
60 8799 171900565 10865337 3309 8 12 9 2210 2210 2757 6 11 7 9 2762 2207 10 12 2758 1660 13 3311 11 7 8 10 10 11 8 2760 1657 10 7 13 14 7 2759 8 2755 3307 9 2211 2210 8 3311 11 10 3862 10 7 8 10 3309 1659 2762 8 4 2209 8 3307 11 5 7 5087 0 0 0 14015 14016 2575 0 0 0 0 4292 14016 0 0 5521 10512 0 632...
output:
4609713219252455
result:
ok 1 number(s): "4609713219252455"
Test #39:
score: 0
Accepted
time: 182ms
memory: 4520kb
input:
60 9071 270184322 20556302 7 2279 10 13 2281 12 2274 10 10 2845 11 2845 8 2277 3413 3981 9 3411 12 9 12 2277 2275 11 8 3412 1712 1712 11 1708 10 10 9 7 10 2842 10 11 10 2841 7 2278 11 2843 10 10 9 1708 10 2846 3973 12 10 6 11 9 2840 7 9 11 0 17208 0 0 17208 0 17208 0 0 6895 0 21509 0 17208 10574 745...
output:
1877379135546875
result:
ok 1 number(s): "1877379135546875"
Test #40:
score: 0
Accepted
time: 144ms
memory: 4484kb
input:
58 8751 184097465 21699552 2196 2199 9 11 8 6 8 2198 12 2742 3839 7 11 7 3841 10 10 2195 11 8 11 2744 11 5 12 1651 3840 9 2197 1650 8 2198 3835 2196 10 2748 2200 10 12 7 12 11 3292 9 2193 1651 12 2743 2198 3836 2746 10 1654 2745 2744 2744 3289 8 14680 14680 0 0 0 0 0 14680 0 6520 11136 0 0 0 5603 0 ...
output:
684171054988125
result:
ok 1 number(s): "684171054988125"