UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196975#3440. 括号Zeardoe1002232ms126680kbC++112.4kb2023-11-04 11:58:422023-11-04 13:05:10

answer

/*
[templates]: 
duipai
spjdp
compre
addhis
floor_sum
treedfs
matrix
network_flow
polynomial
lca
bitset
valuesgt
fenwick
erbitree
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e18;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
mt19937 rng(time(0)); 
int rnd(int l, int r) {return rng() % (r-l+1) + l; }
#define watch(x) cerr  << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
    string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; } 
    reverse(s.begin(), s.end()); cerr << s << endl; 
    return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
const int N = 4000, mod = 998244353; 
int mn[N + 10], tot[N + 10]; int dp[N + 10][N + 10]; 
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen();
    //freopen();
    //time_t start = clock();
    //think twice,code once.
    //think once,debug forever.
    int T; cin >> T;
    while(T--) {
        int n; cin >> n; int ssi = 0; 
        f(i, 1, n) {
            string s; cin >> s; ssi += s.size(); 
            int tmp = 0, stk = 0; 
            for(char ch : s) {
                if(ch == '(') stk ++; 
                else stk --; 
                cmin(tmp, stk); 
            }
            mn[i] = tmp; tot[i] = stk; 
        }
        f(i, 0, n) f(j, 0, ssi) dp[i][j] = 0; 
        dp[0][0] = 1; 
        f(i, 1, n) {
            f(j, 0, ssi) {
                dp[i][j] += dp[i - 1][j]; //不选 i
                if(dp[i][j] >= mod) dp[i][j] -= mod; 
                if(j + mn[i] >= 0) {
                    dp[i][j + tot[i]] += dp[i - 1][j]; //选 i
                    if(dp[i][j + tot[i]] >= mod) dp[i][j + tot[i]] -= mod; 
                }
            }
        }
        cout << dp[n][0] << endl; 
    }

    //time_t finish = clock();
    //cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
    return 0;
}

详细

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1592kb

input:

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

output:

4
2
8
8
4

result:

ok 5 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 1592kb

input:

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

output:

16
2
2
1
4

result:

ok 5 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1592kb

input:

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

output:

2
4
1
1
4

result:

ok 5 lines

Test #4:

score: 10
Accepted
time: 343ms
memory: 126680kb

input:

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

output:

603321095
448173631
393701954
914472959
762538865

result:

ok 5 lines

Test #5:

score: 10
Accepted
time: 363ms
memory: 126680kb

input:

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

output:

528894773
509273114
226219996
829149959
949861738

result:

ok 5 lines

Test #6:

score: 10
Accepted
time: 481ms
memory: 126680kb

input:

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

output:

468794090
809932458
601523255
88872389
655494177

result:

ok 5 lines

Test #7:

score: 10
Accepted
time: 262ms
memory: 123452kb

input:

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

output:

538366364
527886537
501362852
60040777
277351770

result:

ok 5 lines

Test #8:

score: 10
Accepted
time: 264ms
memory: 125108kb

input:

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

output:

715733558
894279974
307698611
108520503
441883588

result:

ok 5 lines

Test #9:

score: 10
Accepted
time: 248ms
memory: 125112kb

input:

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

output:

315075720
609849364
474235717
449851958
472847756

result:

ok 5 lines

Test #10:

score: 10
Accepted
time: 270ms
memory: 124576kb

input:

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

output:

124442224
505965987
545541192
207440322
136942205

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed