UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196948#3440. 括号ddh1231002986ms142244kbC++111.0kb2023-11-04 09:07:302023-11-04 13:01:41

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353
int T,n,len[4005],minn[4005],cnt[4005],ans,dp[4005][4005];
char s[4005][4005];
signed main(){
    scanf("%lld",&T);
    while(T--){
        scanf("%lld",&n);
        memset(dp,0,sizeof(dp));
        memset(cnt,0,sizeof(cnt));
        memset(minn,0x3f,sizeof(minn));
        for(int i=1;i<=n;i++){
            scanf("%s",s[i]+1);
            len[i]=strlen(s[i]+1);
            for(int j=1;j<=len[i];j++){
                cnt[i]+=(s[i][j]=='('?1:-1);
                minn[i]=min(minn[i],cnt[i]);
            }
        }
        ans=dp[0][0]=1;
        for(int i=1;i<=n;i++){
            for(int j=max({-minn[i],-cnt[i],0LL});j+max(0LL,cnt[i])<=4000;j++)
                dp[i][j+cnt[i]]=dp[i-1][j];
            ans=(ans+dp[i][0])%mod,dp[i][0]=(dp[i][0]+dp[i-1][0])%mod;
            for(int j=1;j<=4000;j++)
                dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 114ms
memory: 126604kb

input:

5
10
()((()((())))())()()(())()()()(()(()))()(((()(()((((())))))))())(((()(()((()))))(()))(()()(())(...

output:

4
2
8
8
4

result:

ok 5 lines

Test #2:

score: 10
Accepted
time: 109ms
memory: 126604kb

input:

5
10
()((((()((((()))())))(())))()(()))(())()((((()())()())(()()()((())((()))()(((())))((())()))())(...

output:

16
2
2
1
4

result:

ok 5 lines

Test #3:

score: 10
Accepted
time: 104ms
memory: 126604kb

input:

5
10
()(()(()))()()()()()()(())(()(()((((()()((()))))((()))((())((()))())))))()((()(())()((())())))(...

output:

2
4
1
1
4

result:

ok 5 lines

Test #4:

score: 10
Accepted
time: 436ms
memory: 142244kb

input:

5
3996
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

603321095
448173631
393701954
914472959
762538865

result:

ok 5 lines

Test #5:

score: 10
Accepted
time: 462ms
memory: 142240kb

input:

5
3997
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

528894773
509273114
226219996
829149959
949861738

result:

ok 5 lines

Test #6:

score: 10
Accepted
time: 344ms
memory: 142240kb

input:

5
3996
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

468794090
809932458
601523255
88872389
655494177

result:

ok 5 lines

Test #7:

score: 10
Accepted
time: 367ms
memory: 141836kb

input:

5
2633
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

538366364
527886537
501362852
60040777
277351770

result:

ok 5 lines

Test #8:

score: 10
Accepted
time: 335ms
memory: 142048kb

input:

5
2616
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

715733558
894279974
307698611
108520503
441883588

result:

ok 5 lines

Test #9:

score: 10
Accepted
time: 338ms
memory: 142044kb

input:

5
2622
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

315075720
609849364
474235717
449851958
472847756

result:

ok 5 lines

Test #10:

score: 10
Accepted
time: 377ms
memory: 141976kb

input:

5
2642
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(...

output:

124442224
505965987
545541192
207440322
136942205

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed