QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397540 | #834. Disjoint LIS | iee | AC ✓ | 1713ms | 3844kb | C++14 | 1.2kb | 2024-04-24 11:59:18 | 2024-04-24 11:59:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 998244353;
int power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % P;
a = 1ll * a * a % P;
b /= 2;
}
return res;
}
int main() {
int n;
cin >> n;
int facn = 1;
for (int i = 1; i <= n; i++) {
facn = 1ll * facn * i % P;
}
vector<int> inv(n + 1);
inv[1] = 1;
for (int i = 2; i <= n; i++) {
inv[i] = 1ll * inv[P % i] * (P - P / i) % P;
}
vector<int> len;
int res = 0;
auto count = [&]() {
if (len.size() <= 1 || len[0] != len[1]) {
return;
}
int f = facn;
for (int i = 0; i < len.size(); i++) {
for (int j = 1; j <= len[i]; j++) {
int h = len[i] - j + 1;
for (int k = i + 1; k < len.size(); k++) {
h += len[k] >= j;
}
f = 1ll * f * inv[h] % P;
}
}
(res += 1ll * f * f % P) %= P;
};
function<void(int, int)> dfs = [&](int step, int sum) {
if (step == 0) {
if (sum == n) {
count();
}
return;
}
for (int i = 0; sum + i <= n; i += step) {
for (int j = 0; j < i / step; j++) len.push_back(step);
dfs(step - 1, sum + i);
for (int j = 0; j < i / step; j++) len.pop_back();
}
};
dfs(n, 0);
cout << res << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
input:
6
output:
132
result:
ok 1 number(s): "132"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5
output:
26
result:
ok 1 number(s): "26"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7
output:
834
result:
ok 1 number(s): "834"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
8
output:
6477
result:
ok 1 number(s): "6477"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
9
output:
56242
result:
ok 1 number(s): "56242"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
10
output:
532712
result:
ok 1 number(s): "532712"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
11
output:
5561524
result:
ok 1 number(s): "5561524"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
12
output:
64098432
result:
ok 1 number(s): "64098432"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
13
output:
806184757
result:
ok 1 number(s): "806184757"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
14
output:
948233294
result:
ok 1 number(s): "948233294"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
15
output:
989748344
result:
ok 1 number(s): "989748344"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
16
output:
143602156
result:
ok 1 number(s): "143602156"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
17
output:
634648323
result:
ok 1 number(s): "634648323"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
18
output:
421103776
result:
ok 1 number(s): "421103776"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
19
output:
925864750
result:
ok 1 number(s): "925864750"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
20
output:
797907052
result:
ok 1 number(s): "797907052"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
21
output:
912638617
result:
ok 1 number(s): "912638617"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
22
output:
772780014
result:
ok 1 number(s): "772780014"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
23
output:
386111399
result:
ok 1 number(s): "386111399"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
24
output:
327774735
result:
ok 1 number(s): "327774735"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
25
output:
845702948
result:
ok 1 number(s): "845702948"
Test #26:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
26
output:
791619521
result:
ok 1 number(s): "791619521"
Test #27:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
27
output:
878631164
result:
ok 1 number(s): "878631164"
Test #28:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
28
output:
37336541
result:
ok 1 number(s): "37336541"
Test #29:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
29
output:
165629590
result:
ok 1 number(s): "165629590"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
30
output:
969299909
result:
ok 1 number(s): "969299909"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
31
output:
774782650
result:
ok 1 number(s): "774782650"
Test #32:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
32
output:
860045241
result:
ok 1 number(s): "860045241"
Test #33:
score: 0
Accepted
time: 2ms
memory: 3568kb
input:
33
output:
866378903
result:
ok 1 number(s): "866378903"
Test #34:
score: 0
Accepted
time: 2ms
memory: 3772kb
input:
34
output:
492112739
result:
ok 1 number(s): "492112739"
Test #35:
score: 0
Accepted
time: 2ms
memory: 3832kb
input:
35
output:
824431980
result:
ok 1 number(s): "824431980"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
36
output:
949969944
result:
ok 1 number(s): "949969944"
Test #37:
score: 0
Accepted
time: 3ms
memory: 3488kb
input:
37
output:
970248926
result:
ok 1 number(s): "970248926"
Test #38:
score: 0
Accepted
time: 4ms
memory: 3608kb
input:
38
output:
278772092
result:
ok 1 number(s): "278772092"
Test #39:
score: 0
Accepted
time: 4ms
memory: 3544kb
input:
39
output:
118910029
result:
ok 1 number(s): "118910029"
Test #40:
score: 0
Accepted
time: 4ms
memory: 3612kb
input:
40
output:
190687907
result:
ok 1 number(s): "190687907"
Test #41:
score: 0
Accepted
time: 8ms
memory: 3612kb
input:
41
output:
976616702
result:
ok 1 number(s): "976616702"
Test #42:
score: 0
Accepted
time: 7ms
memory: 3612kb
input:
42
output:
231648679
result:
ok 1 number(s): "231648679"
Test #43:
score: 0
Accepted
time: 9ms
memory: 3612kb
input:
43
output:
722078798
result:
ok 1 number(s): "722078798"
Test #44:
score: 0
Accepted
time: 11ms
memory: 3600kb
input:
44
output:
677622359
result:
ok 1 number(s): "677622359"
Test #45:
score: 0
Accepted
time: 9ms
memory: 3608kb
input:
45
output:
166145100
result:
ok 1 number(s): "166145100"
Test #46:
score: 0
Accepted
time: 11ms
memory: 3612kb
input:
46
output:
322790432
result:
ok 1 number(s): "322790432"
Test #47:
score: 0
Accepted
time: 18ms
memory: 3612kb
input:
47
output:
114852733
result:
ok 1 number(s): "114852733"
Test #48:
score: 0
Accepted
time: 22ms
memory: 3608kb
input:
48
output:
809056236
result:
ok 1 number(s): "809056236"
Test #49:
score: 0
Accepted
time: 26ms
memory: 3544kb
input:
49
output:
133146712
result:
ok 1 number(s): "133146712"
Test #50:
score: 0
Accepted
time: 31ms
memory: 3548kb
input:
50
output:
978647108
result:
ok 1 number(s): "978647108"
Test #51:
score: 0
Accepted
time: 37ms
memory: 3492kb
input:
51
output:
363079147
result:
ok 1 number(s): "363079147"
Test #52:
score: 0
Accepted
time: 44ms
memory: 3548kb
input:
52
output:
447411358
result:
ok 1 number(s): "447411358"
Test #53:
score: 0
Accepted
time: 52ms
memory: 3608kb
input:
53
output:
261833982
result:
ok 1 number(s): "261833982"
Test #54:
score: 0
Accepted
time: 62ms
memory: 3584kb
input:
54
output:
586593658
result:
ok 1 number(s): "586593658"
Test #55:
score: 0
Accepted
time: 74ms
memory: 3544kb
input:
55
output:
543018772
result:
ok 1 number(s): "543018772"
Test #56:
score: 0
Accepted
time: 86ms
memory: 3608kb
input:
56
output:
281510931
result:
ok 1 number(s): "281510931"
Test #57:
score: 0
Accepted
time: 99ms
memory: 3804kb
input:
57
output:
509498959
result:
ok 1 number(s): "509498959"
Test #58:
score: 0
Accepted
time: 121ms
memory: 3548kb
input:
58
output:
499059113
result:
ok 1 number(s): "499059113"
Test #59:
score: 0
Accepted
time: 143ms
memory: 3808kb
input:
59
output:
216456979
result:
ok 1 number(s): "216456979"
Test #60:
score: 0
Accepted
time: 168ms
memory: 3836kb
input:
60
output:
892597175
result:
ok 1 number(s): "892597175"
Test #61:
score: 0
Accepted
time: 198ms
memory: 3508kb
input:
61
output:
288388296
result:
ok 1 number(s): "288388296"
Test #62:
score: 0
Accepted
time: 233ms
memory: 3840kb
input:
62
output:
782889761
result:
ok 1 number(s): "782889761"
Test #63:
score: 0
Accepted
time: 269ms
memory: 3608kb
input:
63
output:
259994934
result:
ok 1 number(s): "259994934"
Test #64:
score: 0
Accepted
time: 320ms
memory: 3612kb
input:
64
output:
668319048
result:
ok 1 number(s): "668319048"
Test #65:
score: 0
Accepted
time: 375ms
memory: 3552kb
input:
65
output:
447568639
result:
ok 1 number(s): "447568639"
Test #66:
score: 0
Accepted
time: 438ms
memory: 3568kb
input:
66
output:
974154792
result:
ok 1 number(s): "974154792"
Test #67:
score: 0
Accepted
time: 512ms
memory: 3548kb
input:
67
output:
434978721
result:
ok 1 number(s): "434978721"
Test #68:
score: 0
Accepted
time: 599ms
memory: 3608kb
input:
68
output:
809640594
result:
ok 1 number(s): "809640594"
Test #69:
score: 0
Accepted
time: 698ms
memory: 3584kb
input:
69
output:
541844549
result:
ok 1 number(s): "541844549"
Test #70:
score: 0
Accepted
time: 812ms
memory: 3644kb
input:
70
output:
9840250
result:
ok 1 number(s): "9840250"
Test #71:
score: 0
Accepted
time: 945ms
memory: 3772kb
input:
71
output:
275431656
result:
ok 1 number(s): "275431656"
Test #72:
score: 0
Accepted
time: 1105ms
memory: 3816kb
input:
72
output:
31040948
result:
ok 1 number(s): "31040948"
Test #73:
score: 0
Accepted
time: 1275ms
memory: 3496kb
input:
73
output:
964592956
result:
ok 1 number(s): "964592956"
Test #74:
score: 0
Accepted
time: 1478ms
memory: 3840kb
input:
74
output:
743394989
result:
ok 1 number(s): "743394989"
Test #75:
score: 0
Accepted
time: 1713ms
memory: 3596kb
input:
75
output:
89362287
result:
ok 1 number(s): "89362287"