QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533095 | #4436. Link with Bracket Sequence II | xuzhihaodedie# | WA | 329ms | 9048kb | C++20 | 1.4kb | 2024-08-25 17:10:59 | 2024-08-25 17:11:00 |
Judging History
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define lson 2*p
#define rson 2*p+1
#define x first
#define y second
//#define endl "\n"
const int N=2e5+10;
const int mod=1e9+7;
int n,m;
int dp[505][505][2];
int a[N];
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
if(n&1) {
cout<<0<<endl;
return ;
}
for(int i=0;i<=n;i++) {
for(int j=0;j<=n;j++) {
dp[i][j][0]=dp[i][j][1]=0;
}
}
for(int i=1;i<n;i++) {
if(a[i]!=0&&a[i+1]!=0) {
if(a[i]+a[i+1]==0&&a[i]>0) dp[i][i+1][1]=1;
else dp[i][i+1][1]=0;
} else if(!a[i]&&!a[i+1]) {
dp[i][i+1][1]=m;
} else {
dp[i][i+1][1]=1;
}
}
for(int len=4;len<=n;len+=2) {
for(int i=1;i+len-1<=n;i++) {
int j=i+len-1;
for(int k=i+1;k<=j-2;k+=2) {
dp[i][j][0]=(dp[i][j][0]+(dp[i][k][0]+dp[i][k][1])%mod*dp[k+1][j][1]%mod)%mod;
}
if(a[i]!=0&&a[j]!=0) {
if(a[i]+a[j]==0&&a[i]>0) dp[i][j][1]=(dp[i][j][1]+dp[i+1][j-1][0]+dp[i+1][j-1][1])%mod;
} else if(a[i]==0&&a[j]==0) {
dp[i][j][1]=(dp[i][j][1]+(dp[i+1][j-1][0]+dp[i+1][j-1][1])*m%mod)%mod;
} else {
dp[i][j][1]=(dp[i][j][1]+dp[i+1][j-1][0]+dp[i+1][j-1][1])%mod;
}
}
}
int ans=(dp[1][n][0]+dp[1][n][1])%mod;
cout<<ans<<endl;
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int T=1;
cin>>T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 329ms
memory: 9048kb
input:
20 10 1 1 -1 0 -1 -1 1 -1 1 0 0 10 2 0 1 1 -2 1 -2 -1 1 -2 1 8 5 0 0 4 0 0 2 -2 0 9 5 0 0 0 -3 0 0 0 0 0 8 5 0 1 0 0 0 0 0 0 498 249013689 239722195 0 0 0 -59682797 187213467 0 0 220688278 0 0 -133178217 165866643 -165866643 216987003 55229518 -55229518 -216987003 0 82546192 0 0 0 0 -62330427 -19687...
output:
2 0 160 0 1750 794099921 796396708 180786104 345214555 36228136 1 646409125 790867257 347678716 74014753 960399457 951689409 227852148 343052576 776801212
result:
wrong answer 1st lines differ - expected: '0', found: '2'