結果
問題 | No.1044 正直者大学 |
ユーザー | packer_jp |
提出日時 | 2020-05-01 23:09:24 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 5,542 bytes |
コンパイル時間 | 1,723 ms |
コンパイル使用メモリ | 164,608 KB |
実行使用メモリ | 8,028 KB |
最終ジャッジ日時 | 2024-06-07 11:25:12 |
合計ジャッジ時間 | 2,969 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 16 ms
8,028 KB |
testcase_06 | AC | 24 ms
8,028 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 8 ms
5,704 KB |
testcase_13 | AC | 14 ms
6,360 KB |
testcase_14 | AC | 9 ms
6,104 KB |
testcase_15 | AC | 16 ms
7,644 KB |
testcase_16 | AC | 17 ms
7,512 KB |
testcase_17 | AC | 9 ms
5,464 KB |
testcase_18 | AC | 11 ms
5,472 KB |
testcase_19 | AC | 6 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 5 ms
5,376 KB |
testcase_22 | AC | 7 ms
5,468 KB |
testcase_23 | AC | 13 ms
7,516 KB |
testcase_24 | AC | 9 ms
5,976 KB |
testcase_25 | AC | 8 ms
5,596 KB |
testcase_26 | AC | 13 ms
7,516 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n) for (int i = 1; i <= (n); i++) #define all(x) begin(x), end(x) #define uniq(x) (x).erase(unique(all(x)), end(x)) #define bit(n) (1LL << (n)) #define cdiv(a, b) (((a) - 1) / (b) + 1) #define dump(x) cerr << #x " = " << (x) << endl using vint = vector<int>; using vvint = vector<vint>; using pint = pair<int, int>; using vpint = vector<pint>; template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr long double PI = 3.1415926535897932384626433832795028L; constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { while (b) { swap(a %= b, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template<typename T> void fin(T mes) { cout << mes << endl; exit(0); } template<typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) { os << "(" << rhs.first << ", " << rhs.second << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) { os << "{"; for (auto itr = rhs.begin(); itr != rhs.end(); itr++) { os << *itr << (next(itr) != rhs.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; template<int MOD = 1000000007> struct mod_int { int val; mod_int(long long val_ = 0) : val(val_ % MOD) { if (val < 0) { val += MOD; }} bool operator==(const mod_int &rhs) const { return val == rhs.val; } bool operator!=(const mod_int &rhs) const { return std::rel_ops::operator!=(*this, rhs); } mod_int &operator+=(const mod_int &rhs) { if ((val += rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator-=(const mod_int &rhs) { if ((val += MOD - rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator*=(const mod_int &rhs) { val = (int) ((long long) val * rhs.val % MOD); return *this; } mod_int &operator/=(const mod_int &rhs) { return *this *= rhs.inv(); } mod_int operator+() const { return *this; } mod_int operator-() const { return -val; } mod_int operator++() { return *this += 1; } mod_int operator--() { return *this -= 1; } mod_int operator++(signed) { const mod_int ret(*this); ++*this; return ret; } mod_int operator--(signed) { const mod_int ret(*this); --*this; return ret; } mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; } mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; } mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; } mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; } mod_int inv() const { int a = val, b = MOD, x = 1, u = 0; while (b) { int t = a / b; std::swap(a -= t * b, b); std::swap(x -= t * u, u); } return x; } mod_int pow(long long n) const { if (n < 0) { return pow(-n).inv(); } mod_int ret = 1, mul = *this; while (n) { if (n & 1) { ret *= mul; } mul *= mul; n >>= 1; } return ret; } friend std::istream &operator>>(std::istream &is, mod_int &rhs) { long long v; is >> v; rhs = v; return is; } friend std::ostream &operator<<(std::ostream &os, const mod_int &rhs) { return os << rhs.val; } struct combination { std::vector<mod_int> fact{1, 1}, f_inv{1, 1}, inv{0, 1}; void calc(int n) { while (fact.size() <= n) { int i = fact.size(); fact.push_back(fact[i - 1] * i); inv.push_back(-inv[MOD % i] * (MOD / i)); f_inv.push_back(f_inv[i - 1] * inv[i]); } } mod_int P(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[n - r]); } mod_int C(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[r] * f_inv[n - r]); } mod_int H(int n, int r) { return C(n + r - 1, r); } }; }; using mint = mod_int<>; mint::combination comb; int N, M, K; signed main() { cin >> N >> M >> K; comb.calc(N + M); if (N == 1) { if (N + M - 2 >= K) { fin(comb.fact[M]); } else { fin(0); } } if (M == 1) { if (N + M - 2 >= K) { fin(comb.fact[N]); } else { fin(0); } } mint ans = 0; reps(i, min(N, M)) { if (K > N + M - 2 * i) { break; } ans += comb.fact[N - 1] * comb.fact[M] * comb.C(N - 2, i - 2) * comb.C(M - 1, i - 1); ans += comb.fact[N - 1] * comb.fact[M] * comb.C(N - 2, i - 1) * comb.C(M - 1, i - 1); ans += comb.fact[N - 1] * comb.fact[M] * comb.C(N - 2, i - 1) * comb.C(M - 1, i - 1); ans += comb.fact[N - 1] * comb.fact[M] * comb.C(N - 2, i - 0) * comb.C(M - 1, i - 1); } cout << ans << endl; }