QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623703#7057. Digital Pathbright_ml#WA 2ms12520kbC++201.5kb2024-10-09 13:47:022024-10-09 13:47:03

Judging History

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

  • [2024-10-09 13:47:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12520kb
  • [2024-10-09 13:47:02]
  • 提交

answer

//
// Created by 35395 on 2024/10/9.
//
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1010;
int dp[N][N];
int a[N][N];
const int mod=1e9+7;
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    int dir[4][2]={0,1,1,0,-1,0,0,-1};
    auto dfs=[&](auto &&self,int x,int y){
        if(dp[x][y]!=-1)return dp[x][y];
        int res=0;
        dp[x][y]=0;
        for(int i=0;i<4;i++){
            int xx=x+dir[i][1];
            int yy=y+dir[i][0];
            if(xx<1||xx>n||yy<1||yy>m)continue;
            if(a[xx][yy]!=a[x][y]+1)continue;
            res++;
            dp[x][y]=(self(self,xx,yy)+dp[x][y])%mod;
        }
        if(res==0)return dp[x][y]=1;
        return dp[x][y];
    };
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dfs(dfs,i,j);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int flag=0;
            for(int c=0; c < 4; c++){
                int xx=i+dir[c][1];
                int yy=j+dir[c][0];
                if(xx<1||xx>n||yy<1||yy>m)continue;
                if(a[xx][yy]!=a[i][j]-1)continue;
                flag=1;
            }
            if(flag==0)ans+=dp[i][j];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 12520kb

input:

3 5
1 2 3 8 7
-1 -1 4 5 6
1 2 3 8 7

output:

6

result:

wrong answer 1st lines differ - expected: '4', found: '6'