QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696104#8236. Snake MovexinlengweishangWA 0ms45212kbC++201.6kb2024-10-31 21:32:472024-10-31 21:32:54

Judging History

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

  • [2024-10-31 21:32:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:45212kb
  • [2024-10-31 21:32:47]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;


int dp[3010][3010],f[3010][3010],t[3010][3010],flag[3010][3010];
char s[3010][3010];
int n,m,k;
struct Node{
    int x,y;
}qu[10000000];
int px[4]={1,-1,0,0};
int py[4]={0,0,1,-1};
long long ans;
void bfs(int x,int y){
    int l=1,r=1;
    qu[l].x=x;qu[l].y=y;
    while(l<=r){
        Node t=qu[l];
        for(int i=0;i<4;i++){
            int tx=t.x+px[i],ty=t.y+py[i];
            if(s[tx-1][ty-1]=='#') continue;
            if(tx==0||ty==0||tx==n||ty==m) continue;
            int s=f[tx][ty] > dp[t.x][t.y] ? f[tx][ty]-dp[t.x][t.y]-1 : 0;
            //dp[tx][ty]=min(dp[tx][ty], s+1+dp[t.x][t.y]);
            if(dp[tx][ty]>s+1+dp[t.x][t.y]){
                dp[tx][ty]=s+1+dp[t.x][t.y];
                //flag[tx][ty]=1;
                r++;
                qu[r].x=tx;qu[r].y=ty;
            }
        }
        l++;
    }
}
void slove(){
    int x0,y0;
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=3000;i++){
        for(int q=1;q<=3000;q++){
            dp[i][q]=1000000010;
        }
    } 
    for(int i=1;i<=k;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(i==1) x0=x,y0=y;
        f[x][y]=k-i+1;
    }
    dp[x0][y0]=0;
    for(int i=0;i<n;i++){
        scanf("%s",s[i]); 
    }
    bfs(x0,y0);
}
int main(){
    int T=1;
    while(T--) slove();
    //ll MOD=1<<64;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        ll s=dp[i][j]!=1000000010 ? dp[i][j] : 0;
        ans+=s*s;
        //ans%=MOD;
    }
    //cout<<1;
    printf("%lld", ans);
    //cout<<ans;
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 45212kb

input:

4 5 5
3 5
3 4
3 3
3 2
4 2
.....
.....
.....
.....

output:

530

result:

wrong answer 1st lines differ - expected: '293', found: '530'