QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696382#8236. Snake MoveLightFeatherWA 320ms110072kbC++202.5kb2024-10-31 22:21:172024-10-31 22:21:17

Judging History

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

  • [2024-10-31 22:21:17]
  • 评测
  • 测评结果:WA
  • 用时:320ms
  • 内存:110072kb
  • [2024-10-31 22:21:17]
  • 提交

answer

#include<bits/stdc++.h>
#define PII pair<int,int>
using ll=long long;
using namespace std;
double a[100005];
int mp[3003][3003];
int dis[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,int nx,int ny){
    queue<PII> q;
    q.push({x,y});
    dis[x][y]=0;
    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(it.first==x&&it.second==y&&a==nx&&b==ny) continue;
            if(a<=n&&a>0&&b<=m&&b>0&&mp[a][b]!=inf){
                if(mp[a][b]>dis[it.first][it.second]+1){
                    if(mp[a][b]<dis[a][b]){
                        dis[a][b]=mp[a][b];
                        q.push({a,b});
                    }
                }
                else if(dis[it.first][it.second]+1<dis[a][b]){
                    dis[a][b]=dis[it.first][it.second]+1;
                    q.push({a,b});
                }
            }
        }
    }
}
void bfs2(int x,int y){
    queue<PII> q;
    q.push({x,y});
    dis2[x][y]=0;
    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(dis2[it.first][it.second]+1<dis2[a][b]){
                    dis2[a][b]=dis2[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,sxx,syy;
    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;
        if(i==2) sxx=u,syy=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,sxx,syy);
    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;
            ll p=min(dis[i][j],dis2[i][j]+k-2);
            // cout<<p<<endl;
            ans=ans+p*p;
        }
    }
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    // cin>>T;
    while(T--){
        slove();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 75140kb

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: 4ms
memory: 75572kb

input:

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

output:

14

result:

ok single line: '14'

Test #3:

score: 0
Accepted
time: 3ms
memory: 75780kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: -100
Wrong Answer
time: 320ms
memory: 110072kb

input:

3000 2900 1
1882 526
........................................................................................................#................................................................................................................................................................#................

output:

35110644338148

result:

wrong answer 1st lines differ - expected: '35141960580077', found: '35110644338148'