QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197209 | #4436. Link with Bracket Sequence II | yiyiyi# | WA | 266ms | 12344kb | C++14 | 1.1kb | 2023-10-02 13:17:35 | 2023-10-02 13:17:36 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define sqr(x) ((x)*(x))
#define N 1000
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int mo=1000000007;
inline int read(){
int x=0,w=0;char ch=getchar();
while (!isdigit(ch))w|=ch=='-',ch=getchar();
while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return w?-x:x;
}
ll f[N][N][2];
int a[N];
void solve(){
int n=read(),m=read();
// memset(f,0,sizeof(f));
for (int i=1;i<=n;++i)a[i]=read(),f[i+1][i][0]=f[i+1][i][1]=1;
for (int len=2;len<=n;len+=2){
for (int i=1;i+len-1<=n;++i){
int j=i+len-1;//cout<<i<<" "<<j<<"!!"<<endl;
for (int k=0;k<2;++k)
if (a[i]==-a[j]){
if (a[i])f[i][j][k]=f[i+1][j-1][k];
else f[i][j][k]=1ll*f[i+1][j-1][k]*m%mo;
}else{
if (a[i]&&a[j])f[i][j][k]=0;
else f[i][j][k]=f[i+1][j-1][k];
}
for (int k=i+1;k<j;k+=2)
f[i][j][1]=(f[i][j][1]+1ll*f[i][k][0]*f[k+1][j][1])%mo;
}
}
cout<<f[1][n][1]<<endl;
}
signed main(){
int T=read();
while (T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 266ms
memory: 12344kb
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:
16 0 155 0 1625 353102361 705889152 864255048 528954131 41698491 0 0 0 0 0 295245764 835447996 218415419 844607668 470009948
result:
wrong answer 1st lines differ - expected: '0', found: '16'