QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#63988 | #4807. Melborp Lacissalc | neko_nyaa | AC ✓ | 607ms | 3832kb | C++23 | 2.0kb | 2022-11-23 20:59:20 | 2022-11-23 20:59:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 998244353;
long long modpow(long long n, long long k, long long MOD) {
long long ans = 1;
while (k > 0) {
if (k & 1) ans = (ans*n) % MOD;
n = (n*n) % MOD; k >>= 1;
}
return ans;
}
const int MAX = 5001;
long long ft[MAX];
long long ftinv[MAX];
void init() {
ft[0] = 1;
for (int i = 1; i < MAX; i++) {
ft[i] = (ft[i-1]*i) % M;
}
ftinv[MAX - 1] = modpow(ft[MAX - 1], M-2, M);
for (int i = MAX - 2; i >= 0; i--) {
ftinv[i] = (ftinv[i+1]*(i+1)) % M;
}
}
long long nCk(int n, int k) {
if (k < 0 || k > n) return 0;
if (k == 0 || k == n) return 1;
return ft[n] * (ftinv[k] * ftinv[n-k] % M) % M;
}
int n, k, t, ans;
set<vector<int>> stv;
void generate(int id, int nleft, int tleft, vector<int> cz) {
if (id == -1) {
for (int i = 1; i <= nleft; i++) {
if (tleft >= i*(i-1)/2) {
cz.push_back(i);
generate(nleft, nleft-i, tleft - i*(i-1)/2, cz);
cz.pop_back();
}
}
return;
}
if (tleft == 0) {
for (int i = 0; i < nleft; i++) {
cz.push_back(1);
}
stv.insert(cz);
return;
}
if (id == 1) {
return;
}
int sf = id*(id-1)/2;
while (1) {
generate(id-1, nleft, tleft, cz);
nleft -= id; tleft -= sf; cz.push_back(id);
if (nleft < 0 || tleft < 0) break;
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
init();
cin >> n >> k >> t;
vector<int> cz;
generate(-1, n+1, t, cz);
for (auto v: stv) {
int wae = 1; int cz = k-1;
for (int i = 1; i < v.size();) {
int j = i;
while (j < v.size() && v[i] == v[j]) {
j++;
}
wae = (wae*nCk(cz, j-i)) % M;
cz -= j-i;
i = j;
}
int tmp = nCk(n, v[0]-1), slots = n-(v[0]-1);
for (int i = 1; i < v.size(); i++) {
tmp = (tmp*nCk(slots, v[i])) % M;
slots -= v[i];
}
tmp = (tmp*wae) % M;
ans = (ans + tmp) % M;
//for (int i: v) cout << i << ' ';
// cout << '\n';
// cout << tmp << '\n';
}
cout << ans << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3284kb
input:
2 5 1
output:
12
result:
ok 1 number(s): "12"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
7 10 15
output:
2016
result:
ok 1 number(s): "2016"
Test #3:
score: 0
Accepted
time: 20ms
memory: 3832kb
input:
46 50 171
output:
645560469
result:
ok 1 number(s): "645560469"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
64 64 0
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3504kb
input:
64 64 1
output:
326126263
result:
ok 1 number(s): "326126263"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3344kb
input:
63 64 0
output:
4476118
result:
ok 1 number(s): "4476118"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
11 45 14
output:
963276342
result:
ok 1 number(s): "963276342"
Test #8:
score: 0
Accepted
time: 4ms
memory: 3416kb
input:
35 20 565
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3484kb
input:
3 64 5
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 6ms
memory: 3360kb
input:
35 45 153
output:
181934997
result:
ok 1 number(s): "181934997"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3340kb
input:
3 25 5
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 8ms
memory: 3308kb
input:
35 5 373
output:
740122840
result:
ok 1 number(s): "740122840"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3292kb
input:
3 50 5
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 4ms
memory: 3408kb
input:
35 30 592
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3360kb
input:
3 11 1
output:
540
result:
ok 1 number(s): "540"
Test #16:
score: 0
Accepted
time: 7ms
memory: 3304kb
input:
35 55 352
output:
656633208
result:
ok 1 number(s): "656633208"
Test #17:
score: 0
Accepted
time: 120ms
memory: 3804kb
input:
54 38 356
output:
215089708
result:
ok 1 number(s): "215089708"
Test #18:
score: 0
Accepted
time: 3ms
memory: 3364kb
input:
22 19 189
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 121ms
memory: 3516kb
input:
54 63 401
output:
987604839
result:
ok 1 number(s): "987604839"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
22 43 171
output:
827743481
result:
ok 1 number(s): "827743481"
Test #21:
score: 0
Accepted
time: 124ms
memory: 3468kb
input:
54 24 446
output:
551546514
result:
ok 1 number(s): "551546514"
Test #22:
score: 0
Accepted
time: 3ms
memory: 3324kb
input:
22 4 152
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 136ms
memory: 3436kb
input:
54 48 1306
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
22 29 7
output:
374430631
result:
ok 1 number(s): "374430631"
Test #25:
score: 0
Accepted
time: 132ms
memory: 3364kb
input:
54 9 1351
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: 0
Accepted
time: 2ms
memory: 3284kb
input:
22 54 5
output:
267958047
result:
ok 1 number(s): "267958047"
Test #27:
score: 0
Accepted
time: 607ms
memory: 3292kb
input:
64 32 1315
output:
494251101
result:
ok 1 number(s): "494251101"
Test #28:
score: 0
Accepted
time: 6ms
memory: 3416kb
input:
33 12 332
output:
765350074
result:
ok 1 number(s): "765350074"
Test #29:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
1 57 1
output:
1
result:
ok 1 number(s): "1"
Test #30:
score: 0
Accepted
time: 3ms
memory: 3432kb
input:
33 37 363
output:
0
result:
ok 1 number(s): "0"
Test #31:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
1 17 0
output:
16
result:
ok 1 number(s): "16"
Test #32:
score: 0
Accepted
time: 5ms
memory: 3424kb
input:
33 62 148
output:
871819399
result:
ok 1 number(s): "871819399"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
1 42 0
output:
41
result:
ok 1 number(s): "41"
Test #34:
score: 0
Accepted
time: 3ms
memory: 3504kb
input:
33 23 179
output:
23699248
result:
ok 1 number(s): "23699248"
Test #35:
score: 0
Accepted
time: 3ms
memory: 3400kb
input:
1 3 1
output:
1
result:
ok 1 number(s): "1"
Test #36:
score: 0
Accepted
time: 7ms
memory: 3496kb
input:
33 47 211
output:
267909794
result:
ok 1 number(s): "267909794"
Test #37:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
11 26 32
output:
0
result:
ok 1 number(s): "0"
Test #38:
score: 0
Accepted
time: 24ms
memory: 3500kb
input:
43 6 579
output:
280289125
result:
ok 1 number(s): "280289125"
Test #39:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
11 50 5
output:
865381083
result:
ok 1 number(s): "865381083"
Test #40:
score: 0
Accepted
time: 24ms
memory: 3352kb
input:
43 31 750
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 2ms
memory: 3496kb
input:
11 11 12
output:
753565341
result:
ok 1 number(s): "753565341"
Test #42:
score: 0
Accepted
time: 23ms
memory: 3460kb
input:
43 56 290
output:
575236094
result:
ok 1 number(s): "575236094"
Test #43:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
11 36 52
output:
0
result:
ok 1 number(s): "0"
Test #44:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
44 16 0
output:
0
result:
ok 1 number(s): "0"
Test #45:
score: 0
Accepted
time: 2ms
memory: 3352kb
input:
12 61 31
output:
682427534
result:
ok 1 number(s): "682427534"
Test #46:
score: 0
Accepted
time: 24ms
memory: 3368kb
input:
44 41 365
output:
759457870
result:
ok 1 number(s): "759457870"
Test #47:
score: 0
Accepted
time: 2ms
memory: 3356kb
input:
22 19 70
output:
247296498
result:
ok 1 number(s): "247296498"
Test #48:
score: 0
Accepted
time: 130ms
memory: 3392kb
input:
54 64 444
output:
418216086
result:
ok 1 number(s): "418216086"
Test #49:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
22 44 52
output:
779702126
result:
ok 1 number(s): "779702126"
Test #50:
score: 0
Accepted
time: 139ms
memory: 3340kb
input:
54 25 1303
output:
0
result:
ok 1 number(s): "0"
Test #51:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
22 5 49
output:
219556981
result:
ok 1 number(s): "219556981"
Test #52:
score: 0
Accepted
time: 136ms
memory: 3340kb
input:
54 49 1269
output:
0
result:
ok 1 number(s): "0"
Test #53:
score: 0
Accepted
time: 3ms
memory: 3356kb
input:
22 30 14
output:
719775605
result:
ok 1 number(s): "719775605"
Test #54:
score: 0
Accepted
time: 159ms
memory: 3340kb
input:
54 10 1314
output:
0
result:
ok 1 number(s): "0"
Test #55:
score: 0
Accepted
time: 2ms
memory: 3348kb
input:
22 54 12
output:
325137058
result:
ok 1 number(s): "325137058"
Test #56:
score: 0
Accepted
time: 136ms
memory: 3368kb
input:
54 35 1359
output:
0
result:
ok 1 number(s): "0"
Test #57:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
33 13 335
output:
202725820
result:
ok 1 number(s): "202725820"
Test #58:
score: 0
Accepted
time: 599ms
memory: 3424kb
input:
64 64 2080
output:
1
result:
ok 1 number(s): "1"
Test #59:
score: 0
Accepted
time: 2ms
memory: 3360kb
input:
1 1 0
output:
0
result:
ok 1 number(s): "0"
Test #60:
score: 0
Accepted
time: 0ms
memory: 3292kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #61:
score: 0
Accepted
time: 520ms
memory: 3364kb
input:
63 63 2016
output:
1
result:
ok 1 number(s): "1"