QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188630 | #4916. 抽奖机 | hos_lyric# | 30 | 43ms | 4052kb | C++14 | 6.6kb | 2023-09-26 06:41:12 | 2024-07-04 02:09:32 |
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 <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 = 1'000'000'009;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 410;
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];
}
}
Mint binom(Int n, Int k) {
if (n < 0) {
if (k >= 0) {
return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
} else if (n - k >= 0) {
return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
} else {
return 0;
}
} else {
if (0 <= k && k <= n) {
assert(n < LIM_INV);
return fac[n] * invFac[k] * invFac[n - k];
} else {
return 0;
}
}
}
constexpr Mint OMEGA = 115381398;
const Mint WS[3] = {1, OMEGA, OMEGA * OMEGA};
const Mint INV_WS[3] = {1, OMEGA * OMEGA, OMEGA};
int N, M;
Int K;
vector<int> A, B;
Mint f[130][130], g[130][130];
void dft(const Mint *ws) {
// g[a][b] = [y^az^b] \sum[i,j] (1+y+z)^(N-i-j) (1+wy+w^2z)^i (1+w^2y+wz)^j
memset(g, 0, sizeof(g));
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) {
for (int a0 = 0; a0 <= (N-i-j); ++a0) for (int b0 = 0; b0 <= (N-i-j) - a0; ++b0)
for (int a1 = 0; a1 <= i ; ++a1) for (int b1 = 0; b1 <= i - a1; ++b1)
for (int a2 = 0; a2 <= j ; ++a2) for (int b2 = 0; b2 <= j - a2; ++b2)
{
Mint t = f[i][j];
t *= (fac[N-i-j] * invFac[(N-i-j)-a0-b0] * invFac[a0] * invFac[b0]);
t *= (fac[i] * invFac[i-a1-b1] * invFac[a1] * invFac[b1]);
t *= (fac[j] * invFac[j-a2-b2] * invFac[a2] * invFac[b2]);
t *= ws[(a1 + 2*b1 + 2*a2 + b2) % 3];
g[a0 + a1 + a2][b0 + b1 + b2] += t;
}
}
memcpy(f, g, sizeof(g));
}
int main() {
prepare();
for (; ~scanf("%d%d%lld", &N, &M, &K); ) {
A.resize(M);
B.resize(M);
for (int m = 0; m < M; ++m) {
scanf("%d%d", &A[m], &B[m]);
}
memset(f, 0, sizeof(f));
for (int m = 0; m < M; ++m) {
f[A[m]][B[m]] += 1;
}
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) f[i][j] *= (fac[N] * invFac[N-i-j] * invFac[i] * invFac[j]);
dft(WS);
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) f[i][j] *= (invFac[N] * fac[N-i-j] * fac[i] * fac[j]);
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) f[i][j] = f[i][j].pow(K);
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) f[i][j] *= (fac[N] * invFac[N-i-j] * invFac[i] * invFac[j]);
dft(INV_WS);
const Mint inv3 = Mint(3).pow(-N);
for (int i = 0; i <= N; ++i) for (int j = 0; j <= N - i; ++j) f[i][j] *= inv3;
for (int i = 0; i <= N; ++i) {
for (int j = 0; j <= N - i; ++j) {
if (j) printf(" ");
printf("%u", f[i][j].x);
}
puts("");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 4052kb
input:
3 6 4 1 2 0 1 2 0 3 0 2 1 1 1
output:
4860 14295 14526 4884 14508 29202 14331 14313 14529 4873
result:
ok 10 numbers
Test #2:
score: 5
Accepted
time: 1ms
memory: 3960kb
input:
5 10 10 4 1 2 2 0 4 5 0 1 3 2 1 0 0 3 2 3 0 0 5
output:
339525305 585755378 185119564 514643854 627403284 752839711 1818805 562123248 542722844 188321355 503033527 706641173 41055444 221483535 311599235 868980824 222671225 674863076 7130996 919681572 334277542
result:
ok 21 numbers
Test #3:
score: 5
Accepted
time: 1ms
memory: 3912kb
input:
8 3 5 2 1 1 4 3 1
output:
330670841 765934203 573230583 327599095 291643618 383155903 484592330 535807528 330670841 674108488 172248481 127075963 547620411 538317547 794750014 172248481 731748168 508087511 316342130 536206437 645955453 536206437 287881926 436690606 383155903 637254059 123031804 123031804 758213062 327599095 ...
result:
ok 45 numbers
Test #4:
score: 5
Accepted
time: 43ms
memory: 4036kb
input:
20 20 20 4 5 8 3 0 2 10 5 12 2 3 13 5 5 18 2 4 11 12 7 15 0 8 4 6 11 2 4 15 5 11 0 7 8 6 2 1 16 8 6
output:
447548369 499314842 762933848 531327968 621357642 517525027 523218106 375080505 859922390 844409608 351337700 992204875 303050601 994785424 315924322 160905536 317796428 90377710 154013232 762945318 814834300 917570800 171412181 464958514 311232845 871217848 51140059 54121620 557288439 934419604 854...
result:
ok 231 numbers
Test #5:
score: 5
Accepted
time: 15ms
memory: 4036kb
input:
17 500 999999993 9 5 3 4 16 0 2 9 0 3 0 10 10 2 8 9 2 4 7 4 16 1 3 1 7 4 7 3 6 11 6 11 5 12 2 1 1 5 15 2 3 7 1 7 8 5 6 5 12 4 2 11 6 11 0 11 2 1 14 3 4 8 1 1 12 0 12 4 17 0 5 0 4 0 7 0 8 7 3 6 4 0 8 1 10 6 4 13 5 9 1 6 1 11 2 1 5 3 5 4 0 1 6 9 6 5 1 13 4 2 8 2 1 0 0 8 4 8 16 0 1 7 0 6 11 6 13 4 9 1 ...
output:
73713555 292019854 839027839 32264129 337043770 489124153 762794834 953369461 931933030 201311441 706033020 654720924 667837522 331629386 203866047 146428942 80087808 227951584 107614386 675667983 422684032 430013546 794118469 532250461 480536934 172609641 77205950 581870046 349831672 9943099 800894...
result:
ok 171 numbers
Test #6:
score: 5
Accepted
time: 43ms
memory: 3960kb
input:
20 500 999999999290915342 6 2 3 1 3 17 4 16 2 2 16 3 15 1 18 2 0 20 12 0 17 2 14 2 10 5 3 15 7 4 14 6 20 0 0 17 3 2 4 3 5 1 10 2 2 0 10 5 4 12 2 3 0 20 4 4 8 4 9 1 7 13 6 10 9 3 4 11 6 11 14 4 9 8 17 3 8 3 0 3 10 5 3 2 6 5 8 3 3 7 12 6 13 3 0 20 0 20 3 11 5 13 6 14 8 8 16 4 14 0 4 0 16 4 12 5 1 3 6 ...
output:
347746568 870778417 397274503 837061945 446080085 363005104 172943807 551740479 656312788 201958492 726027566 88056681 668492087 529420087 533940215 602929657 295533841 535298438 884996458 216348826 212489223 105354323 378705296 483680512 980143428 326305478 677037801 412107264 964228052 835458520 1...
result:
ok 231 numbers
Test #7:
score: 0
Time Limit Exceeded
input:
40 100000 20 39 0 28 0 16 0 2 0 23 0 2 0 26 0 3 0 40 0 27 0 20 0 28 0 4 0 11 0 35 0 15 0 24 0 11 0 18 0 27 0 11 0 37 0 29 0 6 0 34 0 13 0 29 0 27 0 39 0 16 0 15 0 32 0 6 0 39 0 2 0 23 0 2 0 20 0 2 0 33 0 4 0 23 0 10 0 28 0 32 0 13 0 15 0 3 0 18 0 31 0 25 0 14 0 27 0 39 0 4 0 25 0 21 0 22 0 18 0 13 0...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
40 100000 999999997 40 0 16 0 19 0 35 0 32 0 36 0 39 0 31 0 16 0 14 0 2 0 29 0 0 0 11 0 34 0 28 0 14 0 34 0 11 0 5 0 37 0 27 0 10 0 20 0 21 0 2 0 24 0 34 0 1 0 21 0 38 0 5 0 26 0 18 0 0 0 35 0 17 0 17 0 0 0 29 0 32 0 32 0 21 0 23 0 10 0 7 0 24 0 25 0 13 0 37 0 22 0 14 0 33 0 34 0 11 0 21 0 30 0 8 0 ...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
50 50 999999994 24 5 12 33 15 1 18 29 15 0 3 21 1 43 36 7 18 17 30 7 4 7 14 35 4 6 36 5 32 2 36 0 16 28 2 18 44 6 12 36 17 22 5 44 15 33 19 2 36 6 47 1 3 6 15 6 15 14 17 19 3 17 35 15 40 5 10 26 4 31 15 8 25 4 13 30 13 36 30 20 13 2 1 23 24 0 8 25 4 26 11 27 47 2 14 22 10 21 25 16
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
40 100000 999999996 2 16 1 37 19 0 12 5 14 24 13 23 6 14 2 7 18 8 7 24 13 5 27 13 14 19 10 25 31 1 1 16 24 0 0 21 0 13 23 7 29 4 0 36 3 11 7 28 7 3 3 7 4 12 11 21 13 15 37 1 14 3 4 32 11 28 22 9 23 16 5 8 4 5 5 18 22 0 2 2 2 3 2 26 29 5 7 1 5 22 6 21 31 7 13 2 37 3 25 3 33 4 7 26 28 3 8 30 12 26 6 1...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
50 100000 999999999542416524 15 0 11 0 16 0 13 0 42 0 11 0 4 0 0 0 46 0 16 0 29 0 13 0 13 0 21 0 3 0 49 0 9 0 38 0 41 0 44 0 35 0 2 0 19 0 35 0 16 0 48 0 32 0 25 0 10 0 49 0 21 0 37 0 15 0 40 0 42 0 4 0 41 0 28 0 26 0 33 0 26 0 43 0 33 0 11 0 23 0 41 0 30 0 1 0 18 0 37 0 24 0 0 0 19 0 46 0 25 0 32 0...
output:
result:
Test #12:
score: 0
Judgement Failed
input:
50 100000 10 27 0 2 0 2 0 35 0 40 0 2 0 41 0 20 0 25 0 43 0 13 0 17 0 44 0 40 0 25 0 35 0 29 0 3 0 31 0 50 0 37 0 42 0 13 0 16 0 30 0 47 0 14 0 46 0 17 0 1 0 18 0 50 0 43 0 8 0 27 0 46 0 21 0 23 0 6 0 41 0 14 0 21 0 32 0 24 0 48 0 34 0 37 0 34 0 17 0 29 0 20 0 41 0 7 0 42 0 40 0 34 0 18 0 3 0 45 0 4...
output:
result:
Test #13:
score: 0
Judgement Failed
input:
80 100000 100 60 15 38 20 11 44 36 28 8 53 34 42 41 26 2 18 13 16 41 17 3 4 21 41 46 11 44 8 18 46 5 37 0 51 4 59 53 21 34 1 15 10 23 56 23 26 11 18 13 43 23 46 23 20 3 43 4 51 5 22 46 32 17 16 18 23 41 39 39 28 53 27 67 11 22 14 4 6 69 3 7 65 6 13 31 29 30 22 0 58 63 17 32 11 51 22 3 60 17 55 18 29...
output:
result:
Test #14:
score: 0
Judgement Failed
input:
100 100000 100 65 15 56 30 41 25 37 39 35 26 44 37 6 35 0 48 5 48 48 14 7 26 27 51 9 25 4 79 1 92 24 48 16 30 2 66 13 6 24 43 2 30 59 28 5 71 51 9 87 0 46 10 23 32 6 54 67 5 48 1 4 2 67 5 50 39 9 70 23 62 37 0 48 49 20 9 24 36 47 47 29 16 36 25 34 21 16 27 77 14 54 8 27 54 31 42 19 2 25 4 49 45 17 8...
output:
result:
Test #15:
score: 0
Judgement Failed
input:
100 100 999999992 49 0 36 0 40 0 61 0 2 0 72 0 39 0 17 0 32 0 67 0 100 0 9 0 59 0 34 0 43 0 58 0 90 0 97 0 15 0 60 0 84 0 88 0 69 0 13 0 48 0 26 0 7 0 63 0 5 0 51 0 33 0 77 0 54 0 35 0 83 0 56 0 78 0 70 0 53 0 74 0 27 0 73 0 16 0 41 0 8 0 28 0 12 0 81 0 46 0 98 0 86 0 11 0 44 0 65 0 45 0 95 0 38 0 4...
output:
result:
Test #16:
score: 0
Judgement Failed
input:
100 100000 999999998 8 34 17 3 39 48 72 20 35 51 38 6 57 5 30 41 7 72 18 32 27 17 0 76 74 20 97 2 26 6 5 81 36 9 52 37 64 21 35 38 5 26 9 7 49 34 9 2 15 35 34 47 1 90 58 41 5 67 32 0 9 24 82 14 39 36 35 8 2 96 60 15 25 57 0 37 20 45 52 1 25 27 12 77 16 10 49 5 25 20 29 64 74 16 33 41 16 18 18 22 45 ...
output:
result:
Test #17:
score: 0
Judgement Failed
input:
100 100000 999999999869682971 65 18 4 93 36 37 57 30 12 36 55 23 38 35 26 18 30 8 9 12 3 48 3 71 34 2 49 36 42 49 45 11 3 81 40 14 23 53 44 18 16 72 60 11 31 59 9 12 54 43 73 6 48 14 55 8 55 1 29 29 13 51 23 58 6 93 21 4 49 6 60 30 10 65 51 48 82 4 5 64 8 60 53 28 71 8 83 6 24 53 3 73 61 18 11 54 75...
output:
result:
Test #18:
score: 0
Judgement Failed
input:
110 100000 999999999536785977 61 4 40 62 32 16 36 32 66 38 4 35 65 42 87 0 55 39 74 4 17 27 21 9 43 67 26 59 5 88 63 25 52 32 39 27 2 10 60 26 72 23 18 49 73 23 16 53 51 25 54 1 11 7 31 18 7 91 1 13 62 31 52 25 20 26 41 53 65 25 38 56 39 47 15 23 57 11 56 25 12 18 74 34 32 11 10 96 1 53 27 39 43 15 ...
output:
result:
Test #19:
score: 0
Judgement Failed
input:
110 100000 999999999495772595 84 1 83 25 42 3 53 14 48 45 42 2 25 79 96 11 21 74 29 59 67 42 56 11 72 36 73 24 49 30 28 24 17 34 59 42 3 50 70 32 54 44 31 41 33 26 47 21 22 39 5 23 28 38 52 52 6 49 95 10 48 14 58 39 11 90 17 8 36 63 21 30 10 92 20 69 62 43 2 88 17 78 50 11 75 17 19 51 34 55 32 58 46...
output:
result:
Test #20:
score: 0
Judgement Failed
input:
120 100000 999999999990988766 70 39 5 17 1 83 61 11 69 45 11 25 92 17 11 99 22 85 59 44 24 52 18 9 104 9 7 92 1 93 76 5 85 13 46 70 90 19 93 24 6 31 74 6 71 29 94 25 17 46 16 11 52 39 35 72 80 26 20 18 49 6 37 65 112 6 37 41 19 26 14 30 1 0 60 33 11 98 16 7 64 23 73 47 22 5 62 12 51 8 8 46 30 81 30 ...