QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293175#7644. Good Splitsbachbeo2007AC ✓123ms6296kbC++233.0kb2023-12-28 22:32:272023-12-28 22:32:27

Judging History

你现在查看的是最新测评结果

  • [2023-12-28 22:32:27]
  • 评测
  • 测评结果:AC
  • 用时:123ms
  • 内存:6296kb
  • [2023-12-28 22:32:27]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
int mod;
const int maxn=405;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int base=131;

int fac[maxn],dfac[maxn],inv[maxn];
int C(int n,int k){
    if(k>n || k<0 || n<0) return 0;
    return fac[n]*dfac[k]%mod*dfac[n-k]%mod;
}
void combi(int n){
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
    dfac[n]=power(fac[n],mod-2);
    for(int i=n;i>=1;i--){
        dfac[i-1]=dfac[i]*i%mod;
        inv[i]=dfac[i]*fac[i-1]%mod;
    }
}
int catalan(int n){
    return (C(2*n,n)-C(2*n,n+1)+mod)%mod;
}

int n,f[maxn],g[maxn],res[maxn];
int dp[maxn][maxn],d[maxn][maxn];

void solve(){
    cin >> n >> mod;
    combi(2*n);
    g[0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++) g[i]=(g[i]+C(2*i,2*j)*catalan(j)%mod*catalan(i-j)%mod)%mod;
    }
    dp[0][0]=1;
    for(int i=1;i<=2*n;i++){
        for(int j=1;j<=i;j++){
            for(int k=1;k<=i;k+=2) dp[i][j]=(dp[i][j]+dp[i-k][j-1]*g[k/2]%mod)%mod;
        }
    }
    f[0]=1;
    for(int i=1;i<=n;i++){
        f[i]=g[i]*power(2,mod-2)%mod;
        for(int j=1;j<i;j++) f[i]=(f[i]-dp[2*i][2*j]*f[j]%mod+mod)%mod;
    }
    d[0][0]=res[0]=1;
    for(int i=1;i<=2*n;i++){
        for(int j=1;j<=i;j++){
            for(int k=1;k<=i;k+=2) d[i][j]=(d[i][j]+d[i-k][j-1]*res[k/2]%mod)%mod;
        }
        if(i%2==0){
            for(int j=1;j<=i/2;j++) res[i/2]=(res[i/2]+d[i][2*j]*f[j])%mod;
            cout << res[i/2] << '\n';
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5800kb

input:

5 998244353

output:

1
3
14
84
592

result:

ok 5 number(s): "1 3 14 84 592"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3980kb

input:

20 998244353

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
337584612
503820623
71483496
12733593
474907036
203223726
565209211
487441118
992424798
625482036

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3964kb

input:

30 147084737

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
43415138
115604731
88255570
6762644
25928144
117374310
119291296
29414136
87790057
136053957
103827626
145662835
60977924
8837626
61475022
108138661
88536961
105609125
140429327
77714436

result:

ok 30 numbers

Test #4:

score: 0
Accepted
time: 3ms
memory: 6080kb

input:

50 259851877

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
77732735
120479281
107558023
219154876
82657644
224090144
253190966
148874121
53920249
82785846
244357960
88406017
106161945
35184035
131007270
222579610
212725099
114435754
64242919
39323449
211238313
156440547
84150382
242052946
50634162
120017303
2...

result:

ok 50 numbers

Test #5:

score: 0
Accepted
time: 17ms
memory: 4980kb

input:

100 175127923

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
162456689
171123145
54532804
71333538
68283136
25628469
138841774
142350839
27676343
15931022
158187457
43201304
18465009
37939972
169592319
94983552
152752931
69017296
46403905
173424585
170947507
7870926
90491276
10182721
58907963
136216980
28163587...

result:

ok 100 numbers

Test #6:

score: 0
Accepted
time: 50ms
memory: 5972kb

input:

150 367542041

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
337584612
190675313
252320457
264200037
124276323
161424010
184935571
230223063
343780965
314302578
342350468
265272499
173792750
339843799
301192856
263531782
208259173
113525686
44197147
288967350
139023077
142942582
324678736
318907769
315638511
40...

result:

ok 150 numbers

Test #7:

score: 0
Accepted
time: 87ms
memory: 6004kb

input:

177 861641813

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
337584612
51986430
817568411
233712834
530886113
262319436
602763301
391560421
714952237
234059952
504165773
214901044
343336951
654631331
578657419
506328910
26764748
407306588
36662800
819329882
372916107
103054885
512356475
207029843
192047130
1038...

result:

ok 177 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

1 998244353

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 123ms
memory: 6180kb

input:

200 864048671

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
337584612
42358998
716480375
849841780
472934607
500922480
184767796
279937457
399183954
512063087
91797677
107549673
485929841
293677006
593203756
235501697
372544850
500179291
849823101
602694217
345293985
459931747
386664093
196167251
265892579
252...

result:

ok 200 numbers

Test #10:

score: 0
Accepted
time: 117ms
memory: 6296kb

input:

199 958494587

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
337584612
623069921
583730251
536976835
256616783
340763703
344818742
765288755
200573977
666742925
957661404
606909377
32714935
246057767
23198149
389527637
588746573
223336510
430768410
501175382
380964997
647932740
845833201
113681916
396614824
546...

result:

ok 199 numbers

Test #11:

score: 0
Accepted
time: 122ms
memory: 6148kb

input:

198 165619889

output:

1
3
14
84
592
4659
39699
359004
3399164
33378417
6344834
20536013
73289310
162017284
159458288
100856961
164827673
70631917
154742952
14393421
27830529
37917167
68934527
54693629
76175385
34254720
114820104
69340313
35844068
25551171
137354127
120937326
10672731
81957539
132401938
29387190
74534300
...

result:

ok 198 numbers

Extra Test:

score: 0
Extra Test Passed