QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#83317#1769. 括号序列james1BadCreeper100 ✓350ms11244kbC++141.2kb2023-03-01 13:51:412023-03-01 13:51:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-01 13:51:45]
  • 评测
  • 测评结果:100
  • 用时:350ms
  • 内存:11244kb
  • [2023-03-01 13:51:41]
  • 提交

answer

#include <iostream>
#include <cstdio>

using namespace std;
typedef long long i64;
const int MOD = 1000000007;

int n, k;
char s[505];
i64 f[505][505][6];
// f[0]: **
// f[1]: (..)
// f[2]: (..)**
// f[3]: (..)..(..) 包含 1
// f[4]: **(..) 
// f[5]: **(..)** 包含 0 

int main(void)
{
	scanf("%d%d%s", &n, &k, s + 1);
	for (int i = 1; i <= n; ++i) f[i][i-1][0] = 1;
	for (int len = 1; len <= n; ++len)
		for (int i = 1; i <= n - len + 1; ++i) {
			int j = i + len - 1;
			if (len <= k) f[i][j][0] = f[i][j-1][0] && (s[j] == '*' || s[j] == '?');
			if (len >= 2) {
				if ((s[i] == '(' || s[i] == '?') && (s[j] == ')' || s[j] == '?'))
					f[i][j][1] = (f[i+1][j-1][0] + f[i+1][j-1][2] + f[i+1][j-1][3] + f[i+1][j-1][4]) % MOD;
				for (int k = i; k < j; ++k) {
					f[i][j][2] = (f[i][j][2] + f[i][k][3] * f[k+1][j][0]) % MOD;
					f[i][j][3] = (f[i][j][3] + (f[i][k][2]+f[i][k][3]) * f[k+1][j][1]) % MOD;
					f[i][j][4] = (f[i][j][4] + (f[i][k][4]+f[i][k][5]) * f[k+1][j][1]) % MOD;
					f[i][j][5] = (f[i][j][5] + f[i][k][4] * f[k+1][j][0]) % MOD;
				}
			}
			f[i][j][5] = (f[i][j][5] + f[i][j][0]) % MOD;
			f[i][j][3] = (f[i][j][3] + f[i][j][1]) % MOD;
		}
	printf("%lld\n", f[1][n][3]);
	return 0;
}

详细

Test #1:

score: 5
Accepted
time: 2ms
memory: 3592kb

input:

14 3
???*?(*????)??

output:

600

result:

ok single line: '600'

Test #2:

score: 5
Accepted
time: 2ms
memory: 3660kb

input:

15 7
?()??)???*?????

output:

1443

result:

ok single line: '1443'

Test #3:

score: 5
Accepted
time: 2ms
memory: 3568kb

input:

15 10
??*??????????(?

output:

7801

result:

ok single line: '7801'

Test #4:

score: 5
Accepted
time: 2ms
memory: 3664kb

input:

38 6
?(????(??*??????*????*????(?(*(??*????

output:

804755392

result:

ok single line: '804755392'

Test #5:

score: 5
Accepted
time: 2ms
memory: 3792kb

input:

39 17
?????*???)????(????*????????????*???)??

output:

734493810

result:

ok single line: '734493810'

Test #6:

score: 5
Accepted
time: 2ms
memory: 3920kb

input:

40 2
?*???(???(?*???))??*????*???*??**(???(??

output:

946388230

result:

ok single line: '946388230'

Test #7:

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

input:

40 11
?????*????????)??(??)?(??????*??????????

output:

513756777

result:

ok single line: '513756777'

Test #8:

score: 5
Accepted
time: 2ms
memory: 3724kb

input:

40 26
????)????????*????????????*?????????()??

output:

156637450

result:

ok single line: '156637450'

Test #9:

score: 5
Accepted
time: 1ms
memory: 4344kb

input:

95 3
???)??????????)?????????*???????????(?(???????????()?????(???????**??????(??*??????????***?????

output:

267516104

result:

ok single line: '267516104'

Test #10:

score: 5
Accepted
time: 3ms
memory: 4144kb

input:

98 22
?*??????*???)??????(??)?)????????*??????????(?????))??????*????????????*****?????***????(???????*?

output:

641483452

result:

ok single line: '641483452'

Test #11:

score: 5
Accepted
time: 3ms
memory: 4380kb

input:

99 15
???*????*??)??)??????(????**????(???*??????*??????*???)????*???????**?????????*????????*?*??????)??

output:

195466063

result:

ok single line: '195466063'

Test #12:

score: 5
Accepted
time: 3ms
memory: 4176kb

input:

100 17
???*????(???????*?????(??(??????*???????*???????*?????)??)?????(??????*??????(????*????*???*)????*??

output:

695865604

result:

ok single line: '695865604'

Test #13:

score: 5
Accepted
time: 3ms
memory: 4172kb

input:

100 33
??(???*????)??)????)????????????*?????**????????????*???????????*????????*?*???????))???????*?????)?

output:

114367997

result:

ok single line: '114367997'

Test #14:

score: 5
Accepted
time: 304ms
memory: 11168kb

input:

497 238
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

211791029

result:

ok single line: '211791029'

Test #15:

score: 5
Accepted
time: 313ms
memory: 11216kb

input:

500 463
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

572342110

result:

ok single line: '572342110'

Test #16:

score: 5
Accepted
time: 311ms
memory: 11104kb

input:

491 88
???????????*?????????????*??????*?????*?????***?????*?????????*?????(??**??????????????*??***????????????????*?????????)*????????????????(*????????????????*?*????????????(??????*???????????*??????????*????*?*????????*???????????*?????*??????????*???????*??????**???????*???*???????????????????...

output:

617614760

result:

ok single line: '617614760'

Test #17:

score: 5
Accepted
time: 310ms
memory: 11224kb

input:

498 135
?*?????????????*?????*??*??????*?????????**?*??*?**??*????*?????????????????????????????????*????**???????????*????*????*????*?????*????????????(()?*????????*???(?*???????????????*????????????*?????????????????????????(??*??(????)???*????)????)*???????????*???????(???????**????????????*?????...

output:

637064892

result:

ok single line: '637064892'

Test #18:

score: 5
Accepted
time: 299ms
memory: 11240kb

input:

500 174
??*????(((*???????????????????????*???*???????*???*?????????????*??*?*??**?????(???(??????????????????*)?????????????(????????*????*????*????????????????????*?????????*??????*???*??????????????*?????????????????*???*???????????????????????????????????*?*????????????????????????????*??*??????...

output:

835939342

result:

ok single line: '835939342'

Test #19:

score: 5
Accepted
time: 350ms
memory: 11244kb

input:

500 221
????????????*?*??*?????????*???*??????*(???)???)????(?*?????(??**??*???*??????????*??*?*???????*??????*???????*?????)????*???)??)??*??????????????????*???*???????????????????*????????**????????*?????????*??????*??*?*??????????????????*?*????????*???*??????????*????????????*???????????????*??...

output:

977731606

result:

ok single line: '977731606'

Test #20:

score: 5
Accepted
time: 347ms
memory: 11208kb

input:

500 316
???*?*?????*???*???(??????????????*????(?????????????????*?????????????????????*???????????*??**??????*????????????????*????)???*????????????*?*????????????????????????*?*??*?????????????????????*?????????**?*???**???*????*?????????????????????????????????????*???????*??????????*?**????????*...

output:

875239106

result:

ok single line: '875239106'

Extra Test:

score: 0
Extra Test Passed