QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696432#8236. Snake MoveGLLF234WA 4ms75992kbC++201.7kb2024-10-31 22:34:362024-10-31 22:34:37

Judging History

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

  • [2024-10-31 22:34:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:75992kb
  • [2024-10-31 22:34:36]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
using ll=long long;
using namespace std;
double a[100005];
int mp[3003][3003];
int dis[3003][3003];
// bool vis[3003][3003];
// int dis2[3003][3003];
const int inf=1e9+7;
int xx[5]={0,0,0,1,-1};
int yy[5]={0,1,-1,0,0};
int n,m,k;
#define ull unsigned long long
void bfs(int x,int y){
    queue<PII> q;
    q.push({x,y});
    dis[x][y]=0;
    // vis[x][y]=1;
    while(!q.empty()){
        auto it=q.front();
        q.pop();
        for(int i=1;i<=4;i++){
            int a=it.first+xx[i],b=it.second+yy[i];
            if(a<=n&&a>0&&b<=m&&b>0&&mp[a][b]!=inf){
                if(dis[a][b]>max(mp[a][b],dis[it.first][it.second]+1)){
                    dis[a][b]=max(mp[a][b],dis[it.first][it.second]+1);
                    q.push({a,b});
                }
            }
        }
    }
}
void slove(){
    memset(dis,0x7f,sizeof(dis));
    // memset(dis2,0x7f,sizeof(dis2));
    cin>>n>>m>>k;
    int sx,sy;
    for(int i=1;i<=k;i++){
        int u,v;
        cin>>u>>v;
        mp[u][v]=k-i+1;
        if(i==1) sx=u,sy=v;
    }
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        for(int j=0;j<m;j++){
            if(s[j]=='#') mp[i][j+1]=inf;
        }
    }
    bfs(sx,sy);
    // bfs2(sx,sy);
    ll ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(dis[i][j]==0x7f7f7f7f) continue;
            // cout<<dis[i][j]<<endl;
            ans=ans+dis[i][j]*dis[i][j];
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    // cin>>T;
    while(T--){
        slove();
    }
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 75992kb

input:

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

output:

293

result:

ok single line: '293'

Test #2:

score: 0
Accepted
time: 0ms
memory: 75464kb

input:

2 2 4
1 1
1 2
2 2
2 1
..
..

output:

14

result:

ok single line: '14'

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 75428kb

input:

5 5 3
1 2
1 1
2 1
.....
.###.
.#.#.
.###.
.....

output:

-2984670425213351264

result:

wrong answer 1st lines differ - expected: '407', found: '-2984670425213351264'