UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202814#3498. 我是B题cqzxz10044ms1276kbC++111.3kb2024-02-17 10:15:432024-02-17 12:37:11

answer

#include<bits/stdc++.h>
#define il inline
#define int long long
namespace things{
	il int rd(){
		int f = 1, x = 0;
		char ch = getchar();
		while(ch < '0' || ch > '9'){
			if (ch == '-' ) f = -1;
			ch = getchar();
		}
		while(ch >= '0' && ch <= '9'){
			x = x * 10 + ch - '0';
			ch = getchar();
		}
		return x * f;
	}
	il void wt(int x){
		if (x < 0){
			putchar('-');
			wt(-x);
			return ;
		}
		if (x > 9) wt(x / 10);
		putchar(x % 10 + '0');
	}
	il int max(int x, int y){
		return std::max(x, y);
	}
	il int min(int a, int b){
		return std::min(a, b);
	}
}
using namespace things;
using namespace std;

const int p = 998244535, N = 2005;
int id, n, ans, cnt1, cnt2, x, y, z, res, m, k, q;
string s;
int a[N], sum[N], fac[N];

void init(){
	fac[0] = 1;
	for (int i = 1; i < N; i++) fac[i] = (fac[i - 1] << 1) % p;
}

signed main(){
	id = rd();
	cin >> s;
	n = s.size();
	init();
	for (int i = 1; i <= n; i++){
		if (s[i - 1] == '(') a[i] = 1;
	}
	for (int i = 1; i <= n; i++){
		if (a[i] == 1){
			for (int j = n; j >= 1; j--){
				sum[j] = (sum[j] + sum[j - 1]) % p;
			}
			sum[1] = (sum[1] + fac[i - 1]) % p;
		}
		else{
			ans = (ans + sum[1] * fac[n - i]) % p;
			for (int j = 0; j < n; j++){
				sum[j] = (sum[j] + sum[j + 1]) % p;
			}
		}
	}
	cout << ans % p;
	return 0;
}

详细

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

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 0ms
memory: 1248kb

input:

1
()((())()()

output:

4916

result:

ok 1 number(s): "4916"

Test #2:

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

input:

1
)))(((((())()(

output:

26272

result:

ok 1 number(s): "26272"

Test #3:

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

input:

1
()((((()(((()

output:

10821

result:

ok 1 number(s): "10821"

Test #4:

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

input:

1
()(()(()()

output:

2008

result:

ok 1 number(s): "2008"

Test #5:

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

input:

1
((()()))(((

output:

3360

result:

ok 1 number(s): "3360"

Subtask #2:

score: 20
Accepted

Test #6:

score: 20
Accepted
time: 0ms
memory: 1248kb

input:

2
)()))()())())((())(((()))(()((((()((((()((((()())((()()()()())))(()((()()))(((())()()(()()))())(

output:

753742419

result:

ok 1 number(s): "753742419"

Test #7:

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

input:

2
())(())(()()))))()))()()()()(())))())()))())))()((())))))())()))))(

output:

428582172

result:

ok 1 number(s): "428582172"

Test #8:

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

input:

2
()))(())))()(((()()()))()((()))))()()()(())(()())(()(((()(())()()))()))((())(())))))()()

output:

313146974

result:

ok 1 number(s): "313146974"

Test #9:

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

input:

2
(())((()((()))(()()(()))(()())))()()()))((()())))()()(())())())(()(())))))))((()()())())(()()

output:

314378515

result:

ok 1 number(s): "314378515"

Test #10:

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

input:

2
)())(()))())))())))())(((()(()))())()))))(()()())()()()()()((())()((((()()()((()()(()

output:

315269889

result:

ok 1 number(s): "315269889"

Subtask #3:

score: 20
Accepted

Test #11:

score: 20
Accepted
time: 6ms
memory: 1268kb

input:

3
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

263964268

result:

ok 1 number(s): "263964268"

Test #12:

score: 0
Accepted
time: 6ms
memory: 1268kb

input:

3
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

967848294

result:

ok 1 number(s): "967848294"

Test #13:

score: 0
Accepted
time: 5ms
memory: 1272kb

input:

3
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

441079518

result:

ok 1 number(s): "441079518"

Test #14:

score: 0
Accepted
time: 4ms
memory: 1268kb

input:

3
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

950078749

result:

ok 1 number(s): "950078749"

Test #15:

score: 0
Accepted
time: 4ms
memory: 1268kb

input:

3
((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

92027602

result:

ok 1 number(s): "92027602"

Subtask #4:

score: 40
Accepted

Test #16:

score: 40
Accepted
time: 2ms
memory: 1276kb

input:

4
)()(()(()(()())()))(())()((((()()()))(()))))))()))(((((()()((())()()((()(())()())))()(())(()))))((...

output:

61816419

result:

ok 1 number(s): "61816419"

Test #17:

score: 0
Accepted
time: 5ms
memory: 1272kb

input:

4
))))(()(())(((()))((())())))((()))(((()(()))())())(()((()(()))))()(()(())))(((((((()())(()()()))((...

output:

9799738

result:

ok 1 number(s): "9799738"

Test #18:

score: 0
Accepted
time: 5ms
memory: 1276kb

input:

4
)(((()())())))()())))((())()())())()))((()(()((((()()((((()))())()())())(()((()))(())()())))((((()...

output:

849284235

result:

ok 1 number(s): "849284235"

Test #19:

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

input:

4
)())(()(())(()))))((((()))())))(()(((()(((((()))((())))()())()((()(((((((()((()())())))((()(()))()...

output:

256135722

result:

ok 1 number(s): "256135722"

Test #20:

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

input:

4
)((((((()()(())(()(())))(()))()()()((())))(()(()()(((()()(())()))(())()(())()()())))()()())(((())(...

output:

97276274

result:

ok 1 number(s): "97276274"

Extra Test:

score: 0
Extra Test Passed