QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605861#1769. 括号序列Parsley_100 ✓309ms17856kbC++142.1kb2024-10-02 20:12:472024-10-02 20:12:48

Judging History

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

  • [2024-10-02 20:12:48]
  • 评测
  • 测评结果:100
  • 用时:309ms
  • 内存:17856kb
  • [2024-10-02 20:12:47]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define CHECK cout<<"WALKED"<<endl;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
ll binpow(ll a, ll b, ll mod){ll res = 1;  while (b > 0){if (b & 1) res = res * a % mod;a = a * a % mod;  b >>= 1;  }  return res;}
using namespace std;

const int N = 505, p = 1e9 + 7;
ll f[6][N][N];
char str[N];
int n, lim;
ll S[N][N], SA[N][N], AS[N][N]; // bool cao!!!

bool lbl(char c) { return c == '(' || c == '?';}
bool lbr(char c) { return c == ')' || c == '?';}
bool jgs(char c) { return c == '*' || c == '?';}

void init()
{
	for (int i = 1; i <= n; i++) {
		if (!jgs(str[i])) continue;
		for (int j = i; j <= n && j < i + lim; j++) { // mamipulate k's restriction wisely
			if (!jgs(str[j])) break;
			S[i][j] = 1;
		}
	}
	
	for (int i = 1; i < n; i++)
		if (lbl(str[i]) && lbr(str[i + 1])) 
			f[0][i][i + 1] = f[1][i][i + 1] = f[2][i][i + 1] = 1;
}

int main()
{
	cin >> n >> lim;
	scanf("%s", str + 1);
	init();
	
	// % p;
	
	
	for (int len = 3; len <= n; len ++) { // from 3
		for (int l = 1; l <= n - len + 1; l ++) {
			int r = l + len - 1;
			
			f[2][l][r] = lbl(str[l]) * lbr(str[r]) *
						(S[l + 1][r - 1] + f[0][l + 1][r - 1] + SA[l + 1][r - 1] + AS[l + 1][r - 1]);
			f[2][l][r] %= p;
			f[0][l][r] = f[2][l][r];
			// use f qian 's meaning: avoid redundent counting
			for (int k = l + 1; k < r; k ++)
				f[0][l][r] = (f[0][l][r] + f[2][l][k] * f[0][k + 1][r]) % p;
			
			for (int k = l + 1; k < r; k++) 
				f[0][l][r] = (f[0][l][r] + f[2][l][k] * SA[k + 1][r]) % p;
			
			
			for (int k = max(r - lim + 1, l + 1); k <= r; k++) 
				AS[l][r] = (AS[l][r] + f[0][l][k - 1] * S[k][r]) % p;
			for (int k = l; k <= min(l + lim - 1, r - 1); k++)
				SA[l][r] = (SA[l][r] + S[l][k] * f[0][k + 1][r]) % p;
		}
	}
	f[0][1][n] %= p;
	printf("%d\n", f[0][1][n]);
	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

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

input:

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

output:

600

result:

ok single line: '600'

Test #2:

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

input:

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

output:

1443

result:

ok single line: '1443'

Test #3:

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

input:

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

output:

7801

result:

ok single line: '7801'

Test #4:

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

input:

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

output:

804755392

result:

ok single line: '804755392'

Test #5:

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

input:

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

output:

734493810

result:

ok single line: '734493810'

Test #6:

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

input:

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

output:

946388230

result:

ok single line: '946388230'

Test #7:

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

input:

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

output:

513756777

result:

ok single line: '513756777'

Test #8:

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

input:

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

output:

156637450

result:

ok single line: '156637450'

Test #9:

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

input:

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

output:

267516104

result:

ok single line: '267516104'

Test #10:

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

input:

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

output:

641483452

result:

ok single line: '641483452'

Test #11:

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

input:

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

output:

195466063

result:

ok single line: '195466063'

Test #12:

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

input:

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

output:

695865604

result:

ok single line: '695865604'

Test #13:

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

input:

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

output:

114367997

result:

ok single line: '114367997'

Test #14:

score: 5
Accepted
time: 275ms
memory: 16160kb

input:

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

output:

211791029

result:

ok single line: '211791029'

Test #15:

score: 5
Accepted
time: 309ms
memory: 17856kb

input:

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

output:

572342110

result:

ok single line: '572342110'

Test #16:

score: 5
Accepted
time: 206ms
memory: 16196kb

input:

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

output:

617614760

result:

ok single line: '617614760'

Test #17:

score: 5
Accepted
time: 242ms
memory: 17048kb

input:

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

output:

637064892

result:

ok single line: '637064892'

Test #18:

score: 5
Accepted
time: 261ms
memory: 16548kb

input:

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

output:

835939342

result:

ok single line: '835939342'

Test #19:

score: 5
Accepted
time: 281ms
memory: 16536kb

input:

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

output:

977731606

result:

ok single line: '977731606'

Test #20:

score: 5
Accepted
time: 296ms
memory: 16468kb

input:

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

output:

875239106

result:

ok single line: '875239106'

Extra Test:

score: 0
Extra Test Passed