QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50719 | #4436. Link with Bracket Sequence II | zzxzzx123 | WA | 147ms | 5808kb | C++17 | 2.2kb | 2022-09-28 20:22:47 | 2022-09-28 20:22:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=510;
const ll mod=1e9+7;
int a[N];
ll dp[N][N];
ll get(int x,int y){
if(x>y){
return 1;
}
return dp[x][y];
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
memset(dp,-0x3f,sizeof dp);
for(int i=1;i<n;i++){
if(a[i]>0)
{
if((a[i]+a[i+1])==0)
{
dp[i][i+1]=1;
}else if(!a[i+1])
{
dp[i][i+1]=1;
}
}else if(!a[i])
{
if(!a[i+1])
{
dp[i][i+1]=m;
}else if(a[i+1]<0){
dp[i][i+1]=1;
}
}
}
for(int len=4;len<=n;len+=2)
{
for(int i=1;i+len-1<=n;i++){
int j=i+len-1;
ll x=get(i+1,j-1);
if(a[i]<0) continue;
if(x>0){
if(a[i]>0)
{
if((a[i]+a[j])==0)
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
}else if(!a[i+1])
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
}
}else if(!a[i])
{
if(!a[j])
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+get(i+1,j-1)*m%mod)%mod;
}else if(a[j]<0){
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+get(i+1,j-1))%mod;
}
}
}
// cout<<len<<" debug "<<i<<" "<<j<<" "<<dp[i][j]<<endl;
for(int k=i+1;k<j;k+=2){
//枚举中间的点
ll x=get(i+1,k-1),y=get(k+1,j);
if(x<0||y<0)
{
continue;
}
if(a[i]>0)
{
if((a[i]+a[k])==0)
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+x*y%mod)%mod;
}else if(!a[k])
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+x*y%mod)%mod;
}
}else if(!a[i])
{
if(!a[k])
{
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+x*m%mod*y%mod)%mod;
}else if(a[j]<0){
if(dp[i][j]==-1) dp[i][j]=0;
dp[i][j]=(dp[i][j]+x*y%mod)%mod;
}
}
}
// cout<<len<<" ceil "<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
if(dp[1][n]==-1){
dp[1][n]=0;
}
printf("%lld\n",dp[1][n]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 147ms
memory: 5808kb
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:
-4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -4485090715960753727 -44850...
result:
wrong answer 1st lines differ - expected: '0', found: '-4485090715960753727'