結果
| 問題 |
No.1691 Badugi
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-09-24 23:19:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,487 bytes |
| コンパイル時間 | 4,780 ms |
| コンパイル使用メモリ | 254,164 KB |
| 最終ジャッジ日時 | 2025-01-24 17:46:20 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 5 WA * 12 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;
constexpr int FACT_SIZE = 1000000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
Fact[0] = mint::raw(1);
for(int i = 1; i <= FACT_SIZE; ++i) {
Fact[i] = Fact[i-1] * i;
}
iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
for(int i = FACT_SIZE; i; --i) {
iFact[i-1] = iFact[i] * i;
}
return false;
}();
mint comb(int n, int k) {
if (k == 0) return mint::raw(1);
assert(n >= 0 && k >= 0);
if (k > n) return mint::raw(0);
return Fact[n] * iFact[n - k] * iFact[k];
}
mint icomb(int n, int k) {
return iFact[n] * Fact[n - k] * Fact[k];
}
mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
if (n < k) return 0;
assert(0 <= n);
return Fact[n] * iFact[n - k];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
mint ans;
// mint pre;
if (n >= 3 && m >= 3 && k >= 5) {
ans += comb(n, k) * perm(m, k) * perm(k, 3);
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
rep(_, 2) {
if (n >= 3 && k >= 4) {
ans += perm(n, 3) * perm(m, 2) / 2 * comb(n - 3, k - 4) * perm(m - 2, k - 4);
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
swap(n, m);
}
if (k >= 4) {
// ans += comb(n, 2)* comb(m, 2) * comb(n - 2, k - 4) * perm(m - 2, k - 4);
ans += comb(n, k - 2) * perm(m, k - 2) * comb(k - 2, 2) / 2;
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
if (k >= 6 && n >= 4 && m >= 4) {
// ans += comb(n, k) * perm(m, k) * comb(k, 2) * comb(k - 2, 2) / 2;
ans += comb(n, k - 2) * perm(m, k - 2) * perm(k - 2, 2) * perm(k - 4, 2) / 2;
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
rep(_, 2) {
if (k >= 5 && n >= 4 && m >= 3) {
ans += perm(n, 2) * perm(m, 2) * comb(n - 2, 2) * (m - 2) * comb(n - 4, k - 5) * perm(m - 3, k - 5);
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
if (k >= 4 && n >= 4) {
ans += comb(n, 2) * m * comb(n - 2, 2) * (m - 1) / 2 * comb(n - 4, k - 4) * perm(m - 2, k - 4);
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
swap(n, m);
}
if (k >= 4 && n >= 3 && m >= 3) {
ans += comb(n, 2) * (n - 2) * comb(m, 2) * (m - 2) * comb(n - 3, k - 4) * perm(m - 3, k - 4);
// cerr << (ans - pre).val() << endl;
// pre = ans;
}
rep(_, 2) {
if (n >= 3) {
ans += comb(n, 3) * m * comb(n - 3, k - 3) * perm(m - 1, k - 3);
}
if (n >= 3 && k >= 4) {
ans += comb(n, 3) * perm(m, 2) * 3 * comb(n - 3, k - 4) * perm(m - 2, k - 4);
}
if (n >= 3 && m >= 3 && k >= 5) {
// ans += comb(n, 3) * m * comb(m - 1, 2) * 3 * 2 * comb(n - 3, k - 5) * perm(m - 3, k - 5);
ans += perm(n, 3) * perm(m, 2) / 2 * (m - 2) * comb(n - 3, k - 5) * perm(m - 3, k - 5);
}
swap(n, m);
}
// {
// int cnt = 0;
// rep(s, 1 << n * m) {
// if (__builtin_popcount(s) != k) continue;
// int from = n * m, to = from + 1;
// mf_graph<int> g(n * m + 2);
// rep(i, n) rep(j, m) if (s >> (i * m + j) & 1) g.add_edge(i,n+j,1);
// rep(i, n) g.add_edge(from, i, 1);
// rep(j, m) g.add_edge(n + j, to, 1);
// int f = g.flow(from, to);
// if (f == k - 2) {
// cout << s << endl;
// rep(i, n) rep(j, m) if (s >> (i * m + j) & 1) {
// cout << i << ' ' << j << endl;
// }
// cout << endl;
// cnt++;
// }
// }
// cout << cnt << endl;
// }
cout << ans.val() << endl;
}
Kude