QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620238#8236. Snake MoveHide_In_The_ShadowRE 1ms11876kbC++233.1kb2024-10-07 17:06:462024-10-07 17:07:12

Judging History

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

  • [2024-10-07 17:07:12]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:11876kb
  • [2024-10-07 17:06:46]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fio std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pii pair<int,int>
using namespace std;
template<typename T>void read(T &x){
    x=0;
    char c=getchar();
    T ret=0;
    while(!isdigit(c))ret|=!(c^'-'),c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(ret)x=(~x)+1;
}
template<typename T,typename ...Args>
void read(T &x,Args &...xs){
    read(x);read(xs...);
}
template<typename T>void print(T x){
    if(x<0)putchar('-'),x=(~x)+1;
    if(x>9)print(x/10);
    putchar((x-x/10*10)^48);
}
template<typename T>void wr1(T x){
    print(x);putchar(' ');
}
template<typename T>void wr2(T x){
    print(x);putchar('\n');
}
const int N=3010;
int n,m,k,c1[]={1,0,-1,0},c2[]={0,1,0,-1},snac[N][N];
unsigned ll dis[N][N];
bool sna[N][N];
char mp[N][N];
queue<pair<pii,int>>q;
queue<pair<pii,int>>s;
pii sn[114514];
bool chek(int x,int y) {
    if(x<1||y<1||x>n||y>m||mp[x][y]=='#'||sna[x][y])return 0;
    return 1;
}
void bfs(int x,int y,int K) {
    q.push({{x,y},1});
    while(!q.empty()) {
        int x=q.front().first.first,y=q.front().first.second,now=q.front().second;
        q.pop();
        while(s.front().second-now>=K-1) {
            sna[s.front().first.first][s.front().first.second]=0;
            s.pop();
        }
        for(int i=0;i<=3;++i) {
            int X=x+c1[i],Y=y+c2[i];
            if(chek(X,Y)) {
                if(dis[X][Y]>dis[x][y]+1)dis[X][Y]=dis[x][y]+1,q.push({{X,Y},now-1}),s.push({{X,Y},now-1}),sna[X][Y]=1;
            }
        }
    }
}
int main(){
    read(n,m,k);
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            dis[i][j]=LONG_LONG_MAX;
        }
    }
    for(int i=1;i<=k;++i){
        int x,y;
        read(x,y);
        sn[i]=make_pair(x,y);
        snac[x][y]=i;
    }
    for(int i=k;i>=1;--i) {
        s.push({sn[i],i});
        sna[sn[i].first][sn[i].second]=1;
    }
    for(int i=1;i<=n;++i) {
        scanf("%s",mp[i]+1);
    }
    dis[sn[1].first][sn[1].second]=0;
    bfs(sn[1].first,sn[1].second,k);
    while(!s.empty()) {
        sna[s.front().first.first][s.front().first.second]=0;
        s.pop();
    }
    for(int i=0;i<=3;++i) {
        int x=sn[1].first+c1[i],y=sn[1].second+c2[i];
        if(snac[x][y]) {
            int K=snac[x][y];
            if(dis[x][y]>(unsigned ll)k-K+1) {
                dis[x][y]=k-K+1,q.push({{x,y},1});
                for(int j=K-1;j>=1;--j) {
                    s.push({sn[j],j+1});
                    sna[sn[j].first][sn[j].second]=1;
                }
                bfs(x,y,K);
                while(!s.empty()) {
                    sna[s.front().first.first][s.front().first.second]=0;
                    s.pop();
                }
            }
        }
    }
    unsigned ll ans=0;
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            if(dis[i][j]==LONG_LONG_MAX)dis[i][j]=0;
            ans+=dis[i][j]*dis[i][j];
        }
    }
    print(ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11876kb

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: 1ms
memory: 9888kb

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: 0ms
memory: 9768kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: -100
Runtime Error

input:

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

output:


result: