제출 #27485

#제출 시각아이디문제언어결과실행 시간메모리
27485TAMREFTracks in the Snow (BOI13_tracks)C++11
91.25 / 100
2000 ms494544 KiB
#include <bits/stdc++.h>
#define val(r,c) ((F[r][(c)/16]&((unsigned int)3<<((c)%16*2)))>>((c)%16*2))
using namespace std;
const int mx=4002, ms=4000*4000+1;
vector<vector<int>> G(1,vector<int>());
//vector<int> G[ms];
int rep[ms];
unsigned int F[4000][256];
int ans=0, rt=1, d, n, m, g=1;
void bfs(){
    memset(rep,0,sizeof(rep));
    queue<int> node,dep;
    node.push(rt);
    dep.push(1);
    for(;!node.empty();){
        int now=node.front(), dnow=dep.front();
        node.pop(); dep.pop();
        if(rep[now]) continue;
        rep[now]=1; d=max(d,dnow);
        for(int u : G[now]){
            if(!rep[u]){
                node.push(u);
                dep.push(dnow+1);
            }
        }
    }
}
void input(){
    scanf("%d %d\n",&n,&m);
    int f;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            f=getchar();
            f=(f=='F'?0:(f=='R'?1:2));
            F[i][j/16]|=((unsigned int)f<<(j%16*2));
        }
        getchar();
    }
}
void gennode(){
    for(int now=0;now<n*m;++now){
        if(rep[now]|| val(now/m,now%m)==2) continue;
        //printf("%d %d\n",now/m+1,now%m+1);
        G.push_back(vector<int>());
        stack<int> Q;
        Q.push(now); rep[now]=g;
        int cvar=val(now/m,now%m),var,r;
        for(int p;!Q.empty();){
            p=Q.top(); Q.pop();
            //printf("%d\n",val(p/m,p%m));
            rep[p]=g;
            if(p%m<m-1){
                r=p+1;
                var=val(r/m,r%m);
                if(var==cvar && !rep[r]){
                    rep[r]=g;
                    Q.push(r);
                }
                else if(var!=2){
                    if(rep[r] && var!=cvar && (G[rep[r]].empty() || G[rep[r]].back()!=g)){
                        G[g].push_back(rep[r]);
                        G[rep[r]].push_back(g);
                    }
                }
            }
            if(p%m>0){
                r=p-1;
                var=val(r/m,r%m);
                if(var==cvar && !rep[r]){
                    rep[r]=g;
                    Q.push(r);
                }
                else if(var!=2){
                    if(rep[r] && var!=cvar && (G[rep[r]].empty() || G[rep[r]].back()!=g)){
                        G[g].push_back(rep[r]);
                        G[rep[r]].push_back(g);
                    }
                }
            }
            if(p/m<n-1){
                r=p+m;
                var=val(r/m,r%m);
                if(var==cvar && !rep[r]){
                    rep[r]=g;
                    Q.push(r);
                }
                else if(var!=2){
                    if(rep[r] && var!=cvar && (G[rep[r]].empty() || G[rep[r]].back()!=g)){
                        G[g].push_back(rep[r]);
                        G[rep[r]].push_back(g);
                    }
                }
            }
            if(p/m>0){
                r=p-m;
                var=val(r/m,r%m);
                if(var==cvar && !rep[r]){
                    rep[r]=g;
                    Q.push(r);
                }
                else if(var!=2){
                    if(rep[r] && var!=cvar && (G[rep[r]].empty() || G[rep[r]].back()!=g)){
                        G[g].push_back(rep[r]);
                        G[rep[r]].push_back(g);
                    }
                }
            }
        }
        ++g;
    }
}
int main(){
    input();
    gennode();
/*
    printf("%d\n",g);
    for(int i=1;i<g;i++,puts("")) for(int x : G[i]) printf("%d ",x);
*/
    bfs();
    printf("%d\n",d);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'void input()':
tracks.cpp:29:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d\n",&n,&m);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...