QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#681407 | #6198. 三维立体混元劲 | hos_lyric | 100 ✓ | 1999ms | 121932kb | C++14 | 14.0kb | 2024-10-27 07:33:39 | 2024-10-27 07:33:40 |
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 M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353U;
constexpr unsigned MO2 = 2U * MO;
constexpr int FFT_MAX = 23;
using Mint = ModInt<MO>;
constexpr Mint FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 911660635U, 372528824U, 929031873U, 452798380U, 922799308U, 781712469U, 476477967U, 166035806U, 258648936U, 584193783U, 63912897U, 350007156U, 666702199U, 968855178U, 629671588U, 24514907U, 996173970U, 363395222U, 565042129U, 733596141U, 267099868U, 15311432U};
constexpr Mint INV_FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 86583718U, 509520358U, 337190230U, 87557064U, 609441965U, 135236158U, 304459705U, 685443576U, 381598368U, 335559352U, 129292727U, 358024708U, 814576206U, 708402881U, 283043518U, 3707709U, 121392023U, 704923114U, 950391366U, 428961804U, 382752275U, 469870224U};
constexpr Mint FFT_RATIOS[FFT_MAX] = {911660635U, 509520358U, 369330050U, 332049552U, 983190778U, 123842337U, 238493703U, 975955924U, 603855026U, 856644456U, 131300601U, 842657263U, 730768835U, 942482514U, 806263778U, 151565301U, 510815449U, 503497456U, 743006876U, 741047443U, 56250497U, 867605899U};
constexpr Mint INV_FFT_RATIOS[FFT_MAX] = {86583718U, 372528824U, 373294451U, 645684063U, 112220581U, 692852209U, 155456985U, 797128860U, 90816748U, 860285882U, 927414960U, 354738543U, 109331171U, 293255632U, 535113200U, 308540755U, 121186627U, 608385704U, 438932459U, 359477183U, 824071951U, 103369235U};
// as[rev(i)] <- \sum_j \zeta^(ij) as[j]
void fft(Mint *as, int n) {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
int m = n;
if (m >>= 1) {
for (int i = 0; i < m; ++i) {
const unsigned x = as[i + m].x; // < MO
as[i + m].x = as[i].x + MO - x; // < 2 MO
as[i].x += x; // < 2 MO
}
}
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i + m].x = as[i].x + MO - x; // < 3 MO
as[i].x += x; // < 3 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
for (; m; ) {
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i + m].x = as[i].x + MO - x; // < 4 MO
as[i].x += x; // < 4 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i + m].x = as[i].x + MO - x; // < 3 MO
as[i].x += x; // < 3 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
}
for (int i = 0; i < n; ++i) {
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i].x = (as[i].x >= MO) ? (as[i].x - MO) : as[i].x; // < MO
}
}
// as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
void invFft(Mint *as, int n) {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
int m = 1;
if (m < n >> 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned long long y = as[i].x + MO - as[i + m].x; // < 2 MO
as[i].x += as[i + m].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
m <<= 1;
}
for (; m < n >> 1; m <<= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + (m >> 1); ++i) {
const unsigned long long y = as[i].x + MO2 - as[i + m].x; // < 4 MO
as[i].x += as[i + m].x; // < 4 MO
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
const unsigned long long y = as[i].x + MO - as[i + m].x; // < 2 MO
as[i].x += as[i + m].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m < n) {
for (int i = 0; i < m; ++i) {
const unsigned y = as[i].x + MO2 - as[i + m].x; // < 4 MO
as[i].x += as[i + m].x; // < 4 MO
as[i + m].x = y; // < 4 MO
}
}
const Mint invN = Mint(n).inv();
for (int i = 0; i < n; ++i) {
as[i] *= invN;
}
}
void fft(vector<Mint> &as) {
fft(as.data(), as.size());
}
void invFft(vector<Mint> &as) {
invFft(as.data(), as.size());
}
vector<Mint> convolve(vector<Mint> as, vector<Mint> bs) {
if (as.empty() || bs.empty()) return {};
const int len = as.size() + bs.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
bs.resize(n); fft(bs);
for (int i = 0; i < n; ++i) as[i] *= bs[i];
invFft(as);
as.resize(len);
return as;
}
vector<Mint> square(vector<Mint> as) {
if (as.empty()) return {};
const int len = as.size() + as.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
for (int i = 0; i < n; ++i) as[i] *= as[i];
invFft(as);
as.resize(len);
return as;
}
// m := |as|, n := |bs|
// cs[k] = \sum[i-j=k] as[i] bs[j] (0 <= k <= m-n)
// transpose of ((multiply by bs): K^[0,m-n] -> K^[0,m-1])
vector<Mint> middle(vector<Mint> as, vector<Mint> bs) {
const int m = as.size(), n = bs.size();
assert(m >= n); assert(n >= 1);
int len = 1;
for (; len < m; len <<= 1) {}
as.resize(len, 0);
fft(as);
std::reverse(bs.begin(), bs.end());
bs.resize(len, 0);
fft(bs);
for (int i = 0; i < len; ++i) as[i] *= bs[i];
invFft(as);
as.resize(m);
as.erase(as.begin(), as.begin() + (n - 1));
return as;
}
////////////////////////////////////////////////////////////////////////////////
constexpr int LIM_INV = 1 << 18;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];
void prepare() {
inv[1] = 1;
for (int i = 2; i < LIM_INV; ++i) {
inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
}
fac[0] = invFac[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
fac[i] = fac[i - 1] * i;
invFac[i] = invFac[i - 1] * inv[i];
}
}
// !!!Watch out for stack overflow!!!
template <int MAX_K> struct MultiMul {
int K;
vector<int> N;
vector<int> NN;
int LEN;
vector<int> zw;
MultiMul() {}
explicit MultiMul(const vector<int> &N_) {
build(N_);
}
void build(const vector<int> &N_) {
N = N_;
K = N.size();
NN.resize(K + 1);
NN[0] = 1;
for (int k = 0; k < K; ++k) NN[k + 1] = NN[k] * N[k];
LEN = NN[K];
zw.assign(LEN, 0);
for (int h = 0; h < LEN; ++h) {
for (int k = 1; k < K; ++k) zw[h] += h / NN[k];
if (K) zw[h] %= K;
}
}
vector<int> decode(int h) const {
vector<int> ns(K);
for (int k = 0; k < K; ++k) {
ns[k] = h % N[k];
h /= N[k];
}
return ns;
}
Mint work[3][MAX_K][1 << (MAX_K + 1)];
void clear(int s, int len) {
for (int k = 0; k < K; ++k) fill(work[s][k], work[s][k] + len, 0);
}
void fft(int s, int len) {
for (int k = 0; k < K; ++k) ::fft(work[s][k], len);
}
void invFft(int s, int len) {
for (int k = 0; k < K; ++k) ::invFft(work[s][k], len);
}
void pointwise(int s, int t, int u, int len) {
clear(u, len);
for (int ks = 0; ks < K; ++ks) for (int kt = 0; kt < K; ++kt) {
const int ku = (ks + kt) % K;
for (int h = 0; h < len; ++h) work[u][ku][h] += work[s][ks][h] * work[t][kt][h];
}
}
vector<Mint> mul(const vector<Mint> &as, const vector<Mint> &bs) {
if (K == 0) return {as[0] * bs[0]};
int len = 1;
for (; len < LEN << 1; len <<= 1) {}
clear(0, len);
for (int h = 0; h < LEN; ++h) work[0][zw[h]][h] = as[h];
fft(0, len);
clear(1, len);
for (int h = 0; h < LEN; ++h) work[1][zw[h]][h] = bs[h];
fft(1, len);
pointwise(0, 1, 2, len);
invFft(2, len);
vector<Mint> cs(LEN);
for (int h = 0; h < LEN; ++h) cs[h] = work[2][zw[h]][h];
return cs;
}
vector<Mint> inv(const vector<Mint> &as) {
assert(as[0]);
vector<Mint> bs(LEN, 0);
bs[0] = as[0].inv();
for (int m = 1; m < LEN; m <<= 1) {
// b <- b - (a b - 1) b
clear(0, m << 1);
for (int h = 0; h < m << 1 && h < LEN; ++h) work[0][zw[h]][h] = as[h];
fft(0, m << 1);
clear(1, m << 1);
for (int h = 0; h < m; ++h) work[1][zw[h]][h] = bs[h];
fft(1, m << 1);
pointwise(0, 1, 2, m << 1);
invFft(2, m << 1);
clear(2, m);
for (int k = 0; k < K; ++k) for (int h = m; h < m << 1; ++h) if (h >= LEN || k != zw[h]) work[2][k][h] = 0;
fft(2, m << 1);
pointwise(2, 1, 0, m << 1);
invFft(0, m << 1);
for (int h = m; h < m << 1 && h < LEN; ++h) bs[h] = -work[0][zw[h]][h];
}
return bs;
}
vector<Mint> log(const vector<Mint> &as) {
assert(as[0] == 1);
auto bs = as;
for (int i = 0; i < LEN; ++i) bs[i] *= i;
bs = mul(bs, inv(as));
for (int i = 1; i < LEN; ++i) bs[i] *= ::inv[i];
return bs;
}
};
MultiMul<18> mm;
int main() {
prepare();
int K;
for (; ~scanf("%d", &K); ) {
vector<int> N(K);
for (int k = 0; k < K; ++k) {
scanf("%d", &N[k]);
++N[k];
}
vector<vector<Mint>> A(K, vector<Mint>(K));
for (int k0 = 0; k0 < K; ++k0) for (int k1 = 0; k1 < K; ++k1) {
scanf("%u", &A[k0][k1].x);
}
mm.build(N);
vector<Mint> fs(mm.LEN, 1);
for (int h = 0; h < mm.LEN; ++h) {
const auto ns = mm.decode(h);
for (int k = 0; k < K; ++k) {
fs[h] *= (1 + A[k][k]).pow((Int)ns[k] * (ns[k] - 1) / 2);
}
for (int k0 = 0; k0 < K; ++k0) for (int k1 = k0 + 1; k1 < K; ++k1) {
fs[h] *= (1 + A[k0][k1]).pow(ns[k0] * ns[k1]);
}
for (int k = 0; k < K; ++k) {
fs[h] *= invFac[ns[k]];
}
}
// cerr<<"fs = "<<fs<<endl;
const auto gs = mm.log(fs);
Mint ans = gs[mm.LEN - 1];
for (int k = 0; k < K; ++k) {
ans *= fac[N[k] - 1];
}
printf("%u\n", ans.x);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 11ms
memory: 117432kb
input:
9 1 1 1 1 1 1 1 1 1 384948805 706122936 771367603 567865303 555823600 529230579 129527282 884127978 506313429 706122936 710373501 454063862 207096118 188429046 710954317 699767041 83353522 403852216 771367603 454063862 308846178 153221020 757541901 519051098 39938996 597147560 816252892 567865303 20...
output:
987314490
result:
ok 1 number(s): "987314490"
Test #2:
score: 10
Accepted
time: 8ms
memory: 117704kb
input:
2 1 499 450389270 797166654 797166654 22191765
output:
778276770
result:
ok 1 number(s): "778276770"
Test #3:
score: 10
Accepted
time: 4ms
memory: 117476kb
input:
6 3 1 1 2 2 3 626528531 535503765 134827262 148911569 73107049 299719490 535503765 952244280 568291751 382160155 368474127 599763801 134827262 568291751 192759872 737136305 162023179 627979808 148911569 382160155 737136305 108131513 8851076 98467684 73107049 368474127 162023179 8851076 729223523 196...
output:
523722219
result:
ok 1 number(s): "523722219"
Test #4:
score: 10
Accepted
time: 10ms
memory: 117540kb
input:
4 1 1 2 66 18112789 535187387 963649733 548568110 535187387 143749424 11250312 460641148 963649733 11250312 815977477 356911501 548568110 460641148 356911501 968884778
output:
314027619
result:
ok 1 number(s): "314027619"
Test #5:
score: 10
Accepted
time: 11ms
memory: 117484kb
input:
2 2 332 377917592 624206465 624206465 168041967
output:
807298038
result:
ok 1 number(s): "807298038"
Test #6:
score: 10
Accepted
time: 8ms
memory: 117540kb
input:
7 2 1 3 1 1 2 2 505676529 895240168 155280051 43969107 48431132 902946382 970235401 895240168 49259315 843514886 770644680 817179699 547461263 36245527 155280051 843514886 508119284 195644359 958032752 99880324 405412757 43969107 770644680 195644359 982254365 425419434 150559095 15330088 48431132 81...
output:
580087345
result:
ok 1 number(s): "580087345"
Test #7:
score: 10
Accepted
time: 3ms
memory: 117540kb
input:
4 2 61 1 1 940676924 482196235 588108442 87558861 482196235 30841927 851998052 337821970 588108442 851998052 646838965 201081311 87558861 337821970 201081311 474841453
output:
199856691
result:
ok 1 number(s): "199856691"
Test #8:
score: 10
Accepted
time: 16ms
memory: 117448kb
input:
2 3 249 643669687 941702241 941702241 443303037
output:
989392607
result:
ok 1 number(s): "989392607"
Test #9:
score: 10
Accepted
time: 4ms
memory: 117464kb
input:
5 2 3 3 2 3 23451534 468875565 87900833 805614057 3575999 468875565 836354479 844421182 245227573 689138284 87900833 844421182 945595241 631560128 932341618 805614057 245227573 631560128 199540946 603266826 3575999 689138284 932341618 603266826 977962522
output:
909191827
result:
ok 1 number(s): "909191827"
Test #10:
score: 10
Accepted
time: 8ms
memory: 117548kb
input:
3 6 31 3 198262367 587894527 106507972 587894527 719424730 213831023 106507972 213831023 875624146
output:
100295409
result:
ok 1 number(s): "100295409"
Test #11:
score: 10
Accepted
time: 8ms
memory: 117440kb
input:
2 199 4 559707551 123036463 123036463 740107843
output:
339413780
result:
ok 1 number(s): "339413780"
Test #12:
score: 10
Accepted
time: 3ms
memory: 117444kb
input:
6 3 4 1 2 1 3 451679056 192515309 874469931 915437216 492563792 10396178 192515309 195461861 595184637 444324783 339049247 978253553 874469931 595184637 653427539 363658478 639480200 526092899 915437216 444324783 363658478 950908910 711531203 710507839 492563792 339049247 639480200 711531203 9902723...
output:
623688425
result:
ok 1 number(s): "623688425"
Test #13:
score: 10
Accepted
time: 4ms
memory: 117468kb
input:
3 1 61 4 780502930 500369871 490747832 500369871 847077388 55283759 490747832 55283759 119743109
output:
229543853
result:
ok 1 number(s): "229543853"
Test #14:
score: 10
Accepted
time: 8ms
memory: 117480kb
input:
2 165 5 203528846 960759647 960759647 310174992
output:
726268897
result:
ok 1 number(s): "726268897"
Test #15:
score: 10
Accepted
time: 11ms
memory: 117460kb
input:
5 5 3 2 3 2 956965618 79896337 666703630 235208424 667986330 79896337 85352293 270377153 292952958 329851605 666703630 270377153 520229763 128370307 185339371 235208424 292952958 128370307 808883954 530942748 667986330 329851605 185339371 530942748 101334342
output:
867827755
result:
ok 1 number(s): "867827755"
Test #16:
score: 10
Accepted
time: 8ms
memory: 117392kb
input:
3 5 2 39 712296864 830358697 889527200 830358697 369458389 431100420 889527200 431100420 511543842
output:
698172127
result:
ok 1 number(s): "698172127"
Subtask #2:
score: 10
Accepted
Test #17:
score: 10
Accepted
time: 29ms
memory: 118420kb
input:
1 65535 713543820
output:
272927761
result:
ok 1 number(s): "272927761"
Test #18:
score: 10
Accepted
time: 46ms
memory: 118292kb
input:
1 65536 346983832
output:
153217046
result:
ok 1 number(s): "153217046"
Test #19:
score: 10
Accepted
time: 47ms
memory: 118136kb
input:
1 65537 221976787
output:
740350022
result:
ok 1 number(s): "740350022"
Test #20:
score: 10
Accepted
time: 52ms
memory: 119348kb
input:
1 131071 441886882
output:
548695974
result:
ok 1 number(s): "548695974"
Test #21:
score: 10
Accepted
time: 96ms
memory: 119472kb
input:
1 131072 928510965
output:
163584890
result:
ok 1 number(s): "163584890"
Test #22:
score: 10
Accepted
time: 96ms
memory: 119348kb
input:
1 131073 601938859
output:
606015987
result:
ok 1 number(s): "606015987"
Test #23:
score: 10
Accepted
time: 125ms
memory: 121660kb
input:
1 249999 151127787
output:
468858673
result:
ok 1 number(s): "468858673"
Test #24:
score: 10
Accepted
time: 114ms
memory: 121724kb
input:
1 249998 398257368
output:
626513151
result:
ok 1 number(s): "626513151"
Test #25:
score: 10
Accepted
time: 114ms
memory: 121588kb
input:
1 249997 189340739
output:
544589358
result:
ok 1 number(s): "544589358"
Subtask #3:
score: 15
Accepted
Dependency #2:
100%
Accepted
Test #26:
score: 15
Accepted
time: 198ms
memory: 121784kb
input:
2 1952 127 404656687 608468617 608468617 112039133
output:
368925020
result:
ok 1 number(s): "368925020"
Test #27:
score: 15
Accepted
time: 195ms
memory: 121724kb
input:
2 128 1936 723731931 4584207 4584207 111561302
output:
608652458
result:
ok 1 number(s): "608652458"
Test #28:
score: 15
Accepted
time: 204ms
memory: 121856kb
input:
2 1922 129 311111971 731102731 731102731 252700035
output:
308102100
result:
ok 1 number(s): "308102100"
Test #29:
score: 15
Accepted
time: 196ms
memory: 121684kb
input:
2 255 975 539114340 698998281 698998281 563667122
output:
830414838
result:
ok 1 number(s): "830414838"
Test #30:
score: 15
Accepted
time: 197ms
memory: 121660kb
input:
2 971 256 228838824 254151111 254151111 775729368
output:
298596073
result:
ok 1 number(s): "298596073"
Test #31:
score: 15
Accepted
time: 204ms
memory: 121652kb
input:
2 967 257 25380985 511612343 511612343 141109503
output:
217735543
result:
ok 1 number(s): "217735543"
Test #32:
score: 15
Accepted
time: 200ms
memory: 121736kb
input:
2 511 487 343949806 23894211 23894211 469874790
output:
174512475
result:
ok 1 number(s): "174512475"
Test #33:
score: 15
Accepted
time: 199ms
memory: 121932kb
input:
2 486 512 114872324 318210752 318210752 771926569
output:
803728887
result:
ok 1 number(s): "803728887"
Test #34:
score: 15
Accepted
time: 202ms
memory: 121652kb
input:
2 485 513 475600931 292987748 292987748 166757289
output:
757876238
result:
ok 1 number(s): "757876238"
Test #35:
score: 15
Accepted
time: 195ms
memory: 121588kb
input:
2 1 124999 439224018 182386651 182386651 234755577
output:
408717073
result:
ok 1 number(s): "408717073"
Test #36:
score: 15
Accepted
time: 196ms
memory: 121580kb
input:
2 2 83332 397815438 887727861 887727861 206474726
output:
364058121
result:
ok 1 number(s): "364058121"
Test #37:
score: 15
Accepted
time: 192ms
memory: 121724kb
input:
2 62499 3 103786529 806288114 806288114 798822119
output:
374653087
result:
ok 1 number(s): "374653087"
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #38:
score: 10
Accepted
time: 282ms
memory: 121752kb
input:
3 1 62499 1 655549109 478035568 217913838 478035568 352283086 393733721 217913838 393733721 611255983
output:
879778914
result:
ok 1 number(s): "879778914"
Test #39:
score: 10
Accepted
time: 279ms
memory: 121732kb
input:
3 1 41665 2 939419847 446006074 641831921 446006074 169787884 742250596 641831921 742250596 745974917
output:
125580654
result:
ok 1 number(s): "125580654"
Test #40:
score: 10
Accepted
time: 280ms
memory: 121732kb
input:
3 1 31249 3 577851361 195619522 646464086 195619522 903212121 609510065 646464086 609510065 278090323
output:
922040976
result:
ok 1 number(s): "922040976"
Test #41:
score: 10
Accepted
time: 280ms
memory: 121684kb
input:
3 1 2 41665 281456208 797290405 622887367 797290405 36312519 396956838 622887367 396956838 623231631
output:
130391198
result:
ok 1 number(s): "130391198"
Test #42:
score: 10
Accepted
time: 281ms
memory: 121656kb
input:
3 2 27776 2 662759993 182748896 12531454 182748896 311326704 252659135 12531454 252659135 116906455
output:
921519891
result:
ok 1 number(s): "921519891"
Test #43:
score: 10
Accepted
time: 275ms
memory: 121580kb
input:
3 2 3 20832 776753433 203944992 734299301 203944992 467288186 15492747 734299301 15492747 674487207
output:
920624357
result:
ok 1 number(s): "920624357"
Test #44:
score: 10
Accepted
time: 269ms
memory: 121660kb
input:
3 3 1 31249 451762582 926235661 51631775 926235661 160515762 319015852 51631775 319015852 334779189
output:
531645259
result:
ok 1 number(s): "531645259"
Test #45:
score: 10
Accepted
time: 271ms
memory: 121648kb
input:
3 20832 3 2 73212499 453349007 700922836 453349007 985697129 650759902 700922836 650759902 122214743
output:
750237730
result:
ok 1 number(s): "750237730"
Test #46:
score: 10
Accepted
time: 299ms
memory: 121672kb
input:
3 3 3 15624 954893430 335291200 159475662 335291200 844447126 705491930 159475662 705491930 339801443
output:
946203706
result:
ok 1 number(s): "946203706"
Test #47:
score: 10
Accepted
time: 278ms
memory: 121716kb
input:
3 128 1 967 668760147 656759933 506691474 656759933 307108412 434535380 506691474 434535380 321863008
output:
475929070
result:
ok 1 number(s): "475929070"
Test #48:
score: 10
Accepted
time: 287ms
memory: 121720kb
input:
3 2 128 644 239936067 802132924 712432369 802132924 890018758 118729723 712432369 118729723 500595803
output:
844692625
result:
ok 1 number(s): "844692625"
Test #49:
score: 10
Accepted
time: 293ms
memory: 121732kb
input:
3 483 128 3 411647653 991946589 869836763 991946589 586732498 950740090 869836763 950740090 960968706
output:
251661914
result:
ok 1 number(s): "251661914"
Test #50:
score: 10
Accepted
time: 282ms
memory: 121636kb
input:
3 485 1 256 137145714 895279820 867061246 895279820 7614400 309661974 867061246 309661974 61931964
output:
585458610
result:
ok 1 number(s): "585458610"
Test #51:
score: 10
Accepted
time: 286ms
memory: 121636kb
input:
3 2 256 323 985280523 843761597 716777795 843761597 849927463 6354770 716777795 6354770 273286874
output:
779359539
result:
ok 1 number(s): "779359539"
Test #52:
score: 10
Accepted
time: 275ms
memory: 121832kb
input:
3 256 3 242 706580737 169640982 175220091 169640982 154055530 171863667 175220091 171863667 942266312
output:
565721832
result:
ok 1 number(s): "565721832"
Test #53:
score: 10
Accepted
time: 287ms
memory: 121764kb
input:
3 1 512 242 189606063 484992076 221271826 484992076 284558516 595411291 221271826 595411291 65026468
output:
922084224
result:
ok 1 number(s): "922084224"
Test #54:
score: 10
Accepted
time: 288ms
memory: 121636kb
input:
3 512 2 161 937898683 170762820 197540716 170762820 298931315 956569979 197540716 956569979 3111129
output:
34362594
result:
ok 1 number(s): "34362594"
Test #55:
score: 10
Accepted
time: 288ms
memory: 121660kb
input:
3 120 3 512 898466206 411720599 382358449 411720599 40707643 98063429 382358449 98063429 666160747
output:
294809171
result:
ok 1 number(s): "294809171"
Test #56:
score: 10
Accepted
time: 284ms
memory: 121588kb
input:
3 60 60 66 877735616 2218642 794731289 2218642 258861784 229483394 794731289 229483394 238142221
output:
141853918
result:
ok 1 number(s): "141853918"
Test #57:
score: 10
Accepted
time: 288ms
memory: 121660kb
input:
3 99 24 99 931264459 997585823 65134100 997585823 245394908 17864836 65134100 17864836 57433893
output:
97610710
result:
ok 1 number(s): "97610710"
Subtask #5:
score: 15
Accepted
Test #58:
score: 15
Accepted
time: 963ms
memory: 119440kb
input:
17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 758288252 173153507 349207091 689929470 33865932 310876517 146053393 368679317 338621177 253739202 616265423 850768457 30322400 541268854 420859736 259312482 463877494 173153507 450306205 446950111 543829514 664351928 810986156 923415745 642546832 544697389 13767...
output:
886928850
result:
ok 1 number(s): "886928850"
Test #59:
score: 15
Accepted
time: 958ms
memory: 119428kb
input:
17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 556548328 599820407 943991102 286103655 763818484 830102270 189822017 194324706 941916044 484165204 31829800 262155589 370623119 603353618 264379386 160278520 136686567 599820407 568917633 91054104 212697167 631092579 448604326 280640466 839323044 803689743 63390...
output:
610878526
result:
ok 1 number(s): "610878526"
Test #60:
score: 15
Accepted
time: 972ms
memory: 119660kb
input:
17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 577002262 413498773 388905887 964735997 499023989 168117585 801291404 797199960 172435846 918476515 586688950 676200885 476295650 91333632 101162523 246619203 997070372 413498773 215392938 921676500 42535492 310150538 672599925 164098131 670801166 914584777 41639...
output:
604810629
result:
ok 1 number(s): "604810629"
Test #61:
score: 15
Accepted
time: 958ms
memory: 119364kb
input:
17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 473161153 302928644 132469265 605463169 124480712 728043282 696245686 539242758 931889908 595808675 213618535 970779513 492304868 664498120 442136117 910731452 528787680 302928644 230245063 101094002 154743847 561138648 548192993 674509290 434194629 113403998 905...
output:
606777178
result:
ok 1 number(s): "606777178"
Test #62:
score: 15
Accepted
time: 4ms
memory: 117712kb
input:
1 1 753777866
output:
1
result:
ok 1 number(s): "1"
Subtask #6:
score: 40
Accepted
Dependency #1:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #63:
score: 40
Accepted
time: 196ms
memory: 121800kb
input:
2 124999 1 933936361 730960462 730960462 603005535
output:
819068530
result:
ok 1 number(s): "819068530"
Test #64:
score: 40
Accepted
time: 1100ms
memory: 121324kb
input:
11 1 3 2 2 3 3 2 1 3 1 3 459221064 436264691 139560358 189824391 97814679 440002895 992827691 487211892 268724610 527239702 637174886 436264691 132688209 122426789 5909162 70387168 516400239 253624929 458902716 673405642 938616065 184626747 139560358 122426789 399352092 544006185 444186972 260826412...
output:
676993286
result:
ok 1 number(s): "676993286"
Test #65:
score: 40
Accepted
time: 362ms
memory: 121396kb
input:
4 1 69 85 18 263864095 445623719 636540268 185659857 445623719 949760561 871307705 124847701 636540268 871307705 986449863 322242493 185659857 124847701 322242493 822698724
output:
446658911
result:
ok 1 number(s): "446658911"
Test #66:
score: 40
Accepted
time: 195ms
memory: 121588kb
input:
2 83332 2 317629764 689736235 689736235 190875120
output:
243897150
result:
ok 1 number(s): "243897150"
Test #67:
score: 40
Accepted
time: 1226ms
memory: 121320kb
input:
12 1 2 2 1 2 2 2 1 2 2 2 3 836329361 826399644 84220294 408713772 168198139 892780004 889077669 882603916 296657558 798602292 245038436 978861849 826399644 861442788 912426887 57470221 156982218 607621917 797297243 105641453 134277351 478188091 123527454 923818334 84220294 912426887 771551151 415615...
output:
19918798
result:
ok 1 number(s): "19918798"
Test #68:
score: 40
Accepted
time: 351ms
memory: 120544kb
input:
4 79 7 2 96 534041700 371845491 60074621 714223718 371845491 909812011 789533583 101404276 60074621 789533583 592287832 340620309 714223718 101404276 340620309 75700406
output:
388122168
result:
ok 1 number(s): "388122168"
Test #69:
score: 40
Accepted
time: 193ms
memory: 121568kb
input:
2 62499 3 709170946 845075639 845075639 464452267
output:
228476245
result:
ok 1 number(s): "228476245"
Test #70:
score: 40
Accepted
time: 1250ms
memory: 121736kb
input:
12 2 2 2 1 3 1 2 1 2 1 3 3 726311472 463303244 397264164 236501634 193713957 109848624 563746365 107841781 763327201 420539519 966385178 832372851 463303244 491709512 796084197 895515281 618577545 708923692 172874627 683465165 588437831 755183323 459215946 270011929 397264164 796084197 198763738 400...
output:
294373684
result:
ok 1 number(s): "294373684"
Test #71:
score: 40
Accepted
time: 339ms
memory: 119900kb
input:
4 96 3 4 80 868661703 38438805 490164642 529541129 38438805 113362753 572405562 980913906 490164642 572405562 76899522 298857614 529541129 980913906 298857614 119879686
output:
539772570
result:
ok 1 number(s): "539772570"
Test #72:
score: 40
Accepted
time: 1999ms
memory: 120588kb
input:
17 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 380472670 162171090 801946299 548710156 660051073 673998625 476667082 422583531 773622361 191625619 530153542 965974529 129575654 672836647 915590941 197095752 965999982 162171090 846807991 225376835 309269972 867357552 30466203 433457460 894687290 495877281 1675...
output:
29049012
result:
ok 1 number(s): "29049012"
Test #73:
score: 40
Accepted
time: 1795ms
memory: 120672kb
input:
16 1 1 1 1 1 1 1 1 3 1 1 1 1 2 1 1 329409481 254416481 970215839 286981007 739586521 209645556 967428861 421829909 301694045 496796780 716709474 431663667 948769075 573255969 256935780 97646746 254416481 962154630 616377281 31030857 110409985 664649483 494233481 303609276 124362369 686351166 2296213...
output:
436565792
result:
ok 1 number(s): "436565792"
Test #74:
score: 40
Accepted
time: 1783ms
memory: 120148kb
input:
16 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 392922377 242526513 695625989 350804401 223090235 525149798 43680430 48844616 371123461 409513270 976959597 181202804 506188815 635843268 259856686 838232865 242526513 744420238 492300137 324124075 828514247 85914290 571587399 435518449 994846920 978433038 60874434...
output:
794051651
result:
ok 1 number(s): "794051651"
Test #75:
score: 40
Accepted
time: 803ms
memory: 119668kb
input:
15 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 273808310 91737562 939366603 660267026 41619816 505873817 830322584 214297479 886530127 808505378 541723815 781934368 994728930 438150695 489945054 91737562 382742597 964376845 664956003 497127735 201082917 78093486 272261126 775221672 848187829 117117973 467363532 1...
output:
366668315
result:
ok 1 number(s): "366668315"
Test #76:
score: 40
Accepted
time: 1516ms
memory: 121152kb
input:
14 1 1 4 1 1 1 2 1 1 6 1 1 1 1 385933436 801219656 664847494 539092459 226351995 66308031 522667295 147436842 255356881 10001664 93827904 623877560 906442807 866101699 801219656 95602062 10741341 34686412 75138005 430260012 122964371 978258658 846848551 18860501 510104264 92863110 958639132 55503467...
output:
181072418
result:
ok 1 number(s): "181072418"
Extra Test:
score: 0
Extra Test Passed