QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50721 | #4436. Link with Bracket Sequence II | zzxzzx123 | WA | 301ms | 5768kb | C++17 | 2.2kb | 2022-09-28 20:25:54 | 2022-09-28 20:25:55 |
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]<0) 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]<0) 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]<0) 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]<0) 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]<0) dp[i][j]=0;
dp[i][j]=(dp[i][j]+x*y%mod)%mod;
}else if(!a[k])
{
if(dp[i][j]<0) 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]<0) 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]<0) 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]<0){
dp[1][n]=0;
}
printf("%lld\n",dp[1][n]);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 301ms
memory: 5768kb
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:
0 0 125 0 1125 931889029 0 138191259 35495540 2878978 1 0 0 0 429191340 58680229 613012407 227852148 343052576 776801212
result:
wrong answer 3rd lines differ - expected: '75', found: '125'