QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359307 | #7974. 染色 | wsyear | 40 | 86ms | 5792kb | C++14 | 1.8kb | 2024-03-20 16:06:26 | 2024-03-20 16:06:27 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
const int mod = 998244353;
const int iv2 = (mod + 1) >> 1;
const int maxn = 500010;
int fpw(int a, int p = mod - 2) {
int res = 1;
while (p) {
if (p & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod, p >>= 1;
}
return res;
}
inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
inline int Sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
int n, m, k, fac[maxn], ivf[maxn];
int binom(int x, int y) {
if (x < 0 || y < 0 || x < y) return 0;
return 1ll * fac[x] * ivf[y] % mod * ivf[x - y] % mod;
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cin >> n >> m >> k;
fac[0] = 1;
rep (i, 1, n * m) fac[i] = 1ll * fac[i - 1] * i % mod;
ivf[n * m] = fpw(fac[n * m]);
per (i, n * m, 1) ivf[i - 1] = 1ll * ivf[i] * i % mod;
int ans = 0;
rep (x, 0, n) rep (y, 0, m) {
int sum = 0, cnt = x * (m - y) + y * (n - x);
rep (p, 0, cnt) add(sum, 1ll * ((p & 1) ? mod - 1 : 1) * binom(cnt, p) % mod * binom(n * m - cnt, k - p) % mod);
add(ans, 1ll * sum * binom(n, x) % mod * binom(m, y) % mod * (((x + y) & 1) ? mod - 1 : 1) % mod);
}
rep (i, 1, n + m) ans = 1ll * ans * iv2 % mod;
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 5648kb
input:
3 5 7
output:
105
result:
ok single line: '105'
Test #2:
score: 5
Accepted
time: 1ms
memory: 5776kb
input:
4 4 8
output:
144
result:
ok single line: '144'
Test #3:
score: 5
Accepted
time: 1ms
memory: 5716kb
input:
9 7 53
output:
11271960
result:
ok single line: '11271960'
Test #4:
score: 5
Accepted
time: 1ms
memory: 5740kb
input:
10 10 60
output:
711797984
result:
ok single line: '711797984'
Test #5:
score: 5
Accepted
time: 20ms
memory: 5740kb
input:
50 100 100
output:
684521374
result:
ok single line: '684521374'
Test #6:
score: 5
Accepted
time: 18ms
memory: 5756kb
input:
69 69 99
output:
205514286
result:
ok single line: '205514286'
Test #7:
score: 5
Accepted
time: 86ms
memory: 5792kb
input:
500 10 3232
output:
571588252
result:
ok single line: '571588252'
Test #8:
score: 5
Accepted
time: 20ms
memory: 5672kb
input:
70 70 4800
output:
851456413
result:
ok single line: '851456413'
Test #9:
score: 0
Time Limit Exceeded
input:
100 1000 50000
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
316 316 4238
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
201 479 30001
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
706 706 706
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
2023 233 2023
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
402 402 1000
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
707 333 999
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
600 600 18000
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
389 1047 40001
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
707 707 42837
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
100 5000 32346
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
501 501 251001