結果
問題 | No.1691 Badugi |
ユーザー | yakki |
提出日時 | 2021-09-25 03:56:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 2,881 bytes |
コンパイル時間 | 1,136 ms |
コンパイル使用メモリ | 125,536 KB |
実行使用メモリ | 26,744 KB |
最終ジャッジ日時 | 2024-07-05 11:58:00 |
合計ジャッジ時間 | 2,345 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
26,520 KB |
testcase_01 | AC | 24 ms
26,604 KB |
testcase_02 | AC | 25 ms
26,596 KB |
testcase_03 | AC | 26 ms
26,524 KB |
testcase_04 | AC | 25 ms
26,524 KB |
testcase_05 | AC | 27 ms
26,604 KB |
testcase_06 | AC | 25 ms
26,744 KB |
testcase_07 | AC | 25 ms
26,608 KB |
testcase_08 | AC | 24 ms
26,700 KB |
testcase_09 | AC | 26 ms
26,700 KB |
testcase_10 | AC | 26 ms
26,672 KB |
testcase_11 | AC | 26 ms
26,704 KB |
testcase_12 | AC | 25 ms
26,720 KB |
testcase_13 | AC | 25 ms
26,612 KB |
testcase_14 | AC | 26 ms
26,616 KB |
testcase_15 | AC | 25 ms
26,608 KB |
testcase_16 | AC | 26 ms
26,616 KB |
testcase_17 | AC | 27 ms
26,700 KB |
testcase_18 | AC | 25 ms
26,684 KB |
testcase_19 | AC | 28 ms
26,620 KB |
ソースコード
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<bitset> #include<set> #include<map> #include<stack> #include<queue> #include<deque> #include<list> #include<iomanip> #include<cmath> #include<cstring> #include<functional> #include<cstdio> #include<cstdlib> #include<numeric> #include<ctime> //#include<atcoder/all> using namespace std; //using namespace atcoder; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 //#define MOD 1000000007 #define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-18; using ll = long long; using Pi = pair<int,int>; using Pl = pair<ll,ll>; //using mint = modint998244353; int dh[] = {-1,1,0,0}; int dw[] = {0,0,1,-1}; struct Combination{ vector<long long> _fac,_finv,_inv; const int m = MOD; Combination(int sz) : _fac(sz),_finv(sz),_inv(sz){ _fac[0] = _fac[1] = 1; _finv[0] = _finv[1] = 1; _inv[1] = 1; for(int i = 2; i <= sz; i++){ _fac[i] = _fac[i-1]*i%m; _inv[i] = m-_inv[m%i]*(m/i)%m; _finv[i] = _finv[i-1]*_inv[i]%m; } } inline long long fac(int n){return _fac[n];} inline long long inv(int n){return _inv[n];} inline long long finv(int n){return _finv[n];} long long comb(int n,int k){ if(n < k) return 0; if(n < 0 || k < 0) return 0; return _fac[n]*(_finv[k]*_finv[n-k]%m)%m; } }; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main(){ Combination C(1000000); ll n,m,k; cin >> n >> m >> k; k -= 2; ll all = C.comb(n,k)*C.comb(m,k)%MOD*C.fac(k)%MOD; ll tmpp = k*(k-1)%MOD; ll tmp1 = ((tmpp*(tmpp-1)%MOD*modinv(2,MOD)%MOD -tmpp*modinv(2,MOD)%MOD)%MOD + tmpp*modinv(4,MOD)%MOD)%MOD; tmp1 %= MOD; ll tmp2 = (n-k)*k%MOD*(k-1)%MOD*modinv(3,MOD)%MOD; tmp2 += (tmpp-(k-1))%MOD*(n-k)%MOD*k%MOD*modinv(2,MOD)%MOD; tmp2 %= MOD; ll tmp3 = (n-k)*k%MOD*(k-1 + n-k-1)%MOD*modinv(3,MOD)%MOD*modinv(2,MOD)%MOD; tmp3 += (n-k)*k%MOD*(k-1)%MOD*(n-k-1)%MOD*modinv(4,MOD)%MOD*modinv(2,MOD)%MOD; tmp3 %= MOD; ll tmp4 = (n-k)*k%MOD*(k-1)%MOD*(m-k)%MOD*modinv(4,MOD)%MOD; tmp4 %= MOD; ll tmp5 = (m-k)*k%MOD*(k-1)%MOD*modinv(3,MOD)%MOD; tmp5 += (tmpp-(k-1))%MOD*(m-k)%MOD*k%MOD*modinv(2,MOD)%MOD; tmp5 %= MOD; ll tmp6 = (m-k)*k%MOD*(k-1 + m-k-1)%MOD*modinv(3,MOD)%MOD*modinv(2,MOD)%MOD; tmp6 += (m-k)*k%MOD*(k-1)%MOD*(m-k-1)%MOD*modinv(4,MOD)%MOD*modinv(2,MOD)%MOD; tmp6 %= MOD; ll tmp = (tmp1+tmp2+tmp3+tmp4+tmp5+tmp6)%MOD; if(tmp < 0) tmp += MOD; ll ans = all*tmp%MOD; cout << ans << endl; }