QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120016 | #5749. Directed Vertex Cacti | hos_lyric | AC ✓ | 5ms | 3816kb | C++14 | 4.0kb | 2023-07-06 10:57:54 | 2023-07-06 10:57:58 |
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 <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; }
////////////////////////////////////////////////////////////////////////////////
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>;
int N, M;
int main() {
for (; ~scanf("%d%d", &N, &M); ) {
const Int e = 1LL * N * (N - 1) / 2;
Mint numer = 1, denom = 1;
for (int i = 0; i < M; ++i) {
numer *= (e - i);
denom *= (1 + i);
}
Mint ans = numer / denom;
for (int u = 1; u <= N; ++u) {
ans *= u;
}
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3524kb
input:
3 1
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
4 4
output:
360
result:
ok 1 number(s): "360"
Test #3:
score: 0
Accepted
time: 3ms
memory: 3560kb
input:
39847 348708
output:
983575456
result:
ok 1 number(s): "983575456"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
3 2
output:
18
result:
ok 1 number(s): "18"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
3 3
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3804kb
input:
3 4
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 5ms
memory: 3620kb
input:
3 1000000
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3760kb
input:
4 1
output:
144
result:
ok 1 number(s): "144"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
4 2
output:
360
result:
ok 1 number(s): "360"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
4 3
output:
480
result:
ok 1 number(s): "480"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
4 5
output:
144
result:
ok 1 number(s): "144"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
4 6
output:
24
result:
ok 1 number(s): "24"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
5 1
output:
1200
result:
ok 1 number(s): "1200"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
5 2
output:
5400
result:
ok 1 number(s): "5400"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
5 3
output:
14400
result:
ok 1 number(s): "14400"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
5 4
output:
25200
result:
ok 1 number(s): "25200"
Test #18:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
5 5
output:
30240
result:
ok 1 number(s): "30240"
Test #19:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
5 6
output:
25200
result:
ok 1 number(s): "25200"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
5 7
output:
14400
result:
ok 1 number(s): "14400"
Test #21:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
5 8
output:
5400
result:
ok 1 number(s): "5400"
Test #22:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
5 9
output:
1200
result:
ok 1 number(s): "1200"
Test #23:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
5 10
output:
120
result:
ok 1 number(s): "120"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1000 1
output:
533396879
result:
ok 1 number(s): "533396879"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
1000 100
output:
199484478
result:
ok 1 number(s): "199484478"
Test #26:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
1000 10000
output:
656650652
result:
ok 1 number(s): "656650652"
Test #27:
score: 0
Accepted
time: 5ms
memory: 3804kb
input:
1000 1000000
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 5ms
memory: 3580kb
input:
535164 619302
output:
721871396
result:
ok 1 number(s): "721871396"
Test #29:
score: 0
Accepted
time: 5ms
memory: 3592kb
input:
1000000 1000000
output:
580712335
result:
ok 1 number(s): "580712335"
Test #30:
score: 0
Accepted
time: 5ms
memory: 3596kb
input:
1000000 234534
output:
546630669
result:
ok 1 number(s): "546630669"
Test #31:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
234523 1000000
output:
127869098
result:
ok 1 number(s): "127869098"
Test #32:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
44722 10000
output:
0
result:
ok 1 number(s): "0"