제출 #492215

#제출 시각아이디문제언어결과실행 시간메모리
492215ToroTNTracks in the Snow (BOI13_tracks)C++14
100 / 100
1056 ms111500 KiB
#include<bits/stdc++.h>
using namespace std;
int n,m,dx[]={1,-1,0,0},dy[]={0,0,1,-1},d[4005][4005],u,v,sx,sy,x,y;
char s[4005][4005];
queue<pair<int,int> > q;
vector<pair<int,int> > g;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s[i]+1);
    }
    g.push_back({1,1});
    for(int i=1;;i++)
    {
        //printf("%d\n",i);
        for(int j=0;j<g.size();j++)
        {
            sx=g[j].first;
            sy=g[j].second;
            //printf("%d %d\n",sx,sy);
            q.push({sx,sy});
            d[sx][sy]=1;
        }
        g.clear();
        while(!q.empty())
        {
            u=q.front().first;
            v=q.front().second;
            q.pop();
            for(int j=0;j<4;j++)
            {
                x=u+dx[j];
                y=v+dy[j];
                if(x>=1&&x<=n&&y>=1&&y<=m)
                {
                    if(s[x][y]!='.')
                    {
                        if(s[x][y]!=s[u][v])
                        {
                            if(d[x][y]==0)
                            {
                                sx=x;
                                sy=y;
                                g.push_back({sx,sy});
                            }
                        }else
                        {
                            //printf("%d %d %d %d\n",u,v,x,y);
                            if(d[x][y]==0)
                            {
                                //printf("%d %d %d\n",x,y,d[x][y]);
                                d[x][y]=1;
                                q.push({x,y});
                            }
                        }
                    }
                }
            }
        }
        if(g.size()==0)
        {
            printf("%d\n",i);
            break;
        }
    }
}

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

tracks.cpp: In function 'int main()':
tracks.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int j=0;j<g.size();j++)
      |                     ~^~~~~~~~~
tracks.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%s",s[i]+1);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...