QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563161#1769. 括号序列Elegia100 ✓177ms7688kbC++141.2kb2024-09-14 03:12:362024-09-14 03:12:36

Judging History

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

  • [2024-09-14 03:12:36]
  • 评测
  • 测评结果:100
  • 用时:177ms
  • 内存:7688kb
  • [2024-09-14 03:12:36]
  • 提交

answer

#include <bits/stdc++.h>

typedef unsigned long long ull;

const int P = 1000000007;

void add(int& x, int y) { if ((x += y) >= P) x -= P; }

const int N = 510;

char str[N];
int a[N][N], sa[N][N], as[N][N], pure[N][N];

bool fit(char c, char t) { return c == '?' || c == t; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL); std::cout.tie(NULL);

	int n, k; std::cin >> n >> k >> (str + 1);
	
	for (int len = 2; len <= n; ++len)
		for (int l = 1, r = len; r <= n; ++l, ++r) {
			if (fit(str[l], '(') && fit(str[r], ')')) {
				add(pure[l][r], a[l + 1][r - 1]);
				add(pure[l][r], sa[l + 1][r - 1]);
				add(pure[l][r], as[l + 1][r - 1]);
				bool fl = r - l - 1 <= k;
				for (int i = l + 1; i != r; ++i) fl &= fit(str[i], '*');
				add(pure[l][r], fl);
			}
			add(a[l][r], pure[l][r]);
			for (int i = l; i != r; ++i) a[l][r] = (a[l][r] + pure[l][i] * ((ull)sa[i + 1][r] + a[i + 1][r])) % P;
			for (int i = l; i <= std::min(l + k - 1, r); ++i) {
				if (!fit(str[i], '*')) break;
				add(sa[l][r], a[i + 1][r]);
			}
			for (int i = r; i >= std::max(r - k + 1, l); --i) {
				if (!fit(str[i], '*')) break;
				add(as[l][r], a[l][i - 1]);
			}
		}
	std::cout << a[1][n] << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

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

output:

600

result:

ok single line: '600'

Test #2:

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

input:

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

output:

1443

result:

ok single line: '1443'

Test #3:

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

input:

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

output:

7801

result:

ok single line: '7801'

Test #4:

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

input:

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

output:

804755392

result:

ok single line: '804755392'

Test #5:

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

input:

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

output:

734493810

result:

ok single line: '734493810'

Test #6:

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

input:

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

output:

946388230

result:

ok single line: '946388230'

Test #7:

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

input:

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

output:

513756777

result:

ok single line: '513756777'

Test #8:

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

input:

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

output:

156637450

result:

ok single line: '156637450'

Test #9:

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

input:

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

output:

267516104

result:

ok single line: '267516104'

Test #10:

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

input:

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

output:

641483452

result:

ok single line: '641483452'

Test #11:

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

input:

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

output:

195466063

result:

ok single line: '195466063'

Test #12:

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

input:

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

output:

695865604

result:

ok single line: '695865604'

Test #13:

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

input:

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

output:

114367997

result:

ok single line: '114367997'

Test #14:

score: 5
Accepted
time: 156ms
memory: 7608kb

input:

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

output:

211791029

result:

ok single line: '211791029'

Test #15:

score: 5
Accepted
time: 177ms
memory: 7580kb

input:

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

output:

572342110

result:

ok single line: '572342110'

Test #16:

score: 5
Accepted
time: 94ms
memory: 7560kb

input:

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

output:

617614760

result:

ok single line: '617614760'

Test #17:

score: 5
Accepted
time: 105ms
memory: 7672kb

input:

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

output:

637064892

result:

ok single line: '637064892'

Test #18:

score: 5
Accepted
time: 116ms
memory: 7632kb

input:

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

output:

835939342

result:

ok single line: '835939342'

Test #19:

score: 5
Accepted
time: 128ms
memory: 7688kb

input:

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

output:

977731606

result:

ok single line: '977731606'

Test #20:

score: 5
Accepted
time: 131ms
memory: 7576kb

input:

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

output:

875239106

result:

ok single line: '875239106'

Extra Test:

score: 0
Extra Test Passed