Submission #134066

#TimeUsernameProblemLanguageResultExecution timeMemory
134066wilwxkTracks in the Snow (BOI13_tracks)C++14
86.88 / 100
2125 ms729628 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=4e3+5; const int MAXNN=16000005; vector<int> g[MAXNN]; short cor[MAXNN]; short marc[MAXNN]; short ori[MAXN][MAXN]; char c[MAXN]; int rep[MAXNN], tam[MAXNN], dist[MAXNN]; vector<int> qu; int dx[]={0, 1, 0, -1}; int dy[]={1, 0, -1, 0}; int n, m, respf; int find(int cur) { if(rep[cur]==cur) return cur; return rep[cur]=find(rep[cur]); } void une(int a, int b) { a=find(a); b=find(b); if(a==b) return; if(tam[a]<tam[b]) swap(a, b); rep[a]=b; } void liga(int a, int b) { a=find(a); b=find(b); g[a].push_back(b); g[b].push_back(a); // printf("liga %d %d\n", a, b); } void bfs() { qu.push_back(find(0)); dist[find(0)]=1; int ind=0; while(ind<qu.size()) { int cur=qu[ind++]; cur=find(cur); if(marc[cur]==2) continue; marc[cur]=2; respf=max(respf, dist[cur]); for(auto viz : g[cur]) { if(marc[find(viz)]!=0) continue; qu.push_back(find(viz)); dist[viz]=dist[cur]+1; marc[find(viz)]=1; } } } int main() { scanf("%d %d", &n, &m); srand(time(0)); for(int i=0; i<n; i++) for(int j=0; j<m; j++) rep[i*m+j]=tam[i*m+j]=i*m+j; // random_shuffle(tam, tam+(n*m)); for(int i=0; i<n; i++) { scanf(" %s", c); for(int j=0; j<m; j++) { if(c[j]=='.') ori[i][j]=0; else if(c[j]=='F') ori[i][j]=1; else ori[i][j]=2; cor[i*m+j]=ori[i][j]; } } for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { int cur=i*m+j; if(!cor[cur]) continue; for(int k=0; k<4; k++) { int ii=i+dx[k]; int jj=j+dy[k]; if(ii<0||jj<0||ii>=n||jj>=m) continue; int viz=ii*m+jj; if(!cor[viz]) continue; if(ori[i][j]==ori[ii][jj]) une(cur, viz); } } } for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { int cur=i*m+j; if(!cor[cur]) continue; for(int k=0; k<4; k++) { int ii=i+dx[k]; int jj=j+dy[k]; if(ii<0||jj<0||ii>=n||jj>=m) continue; int viz=ii*m+jj; if(!cor[viz]) continue; if(cor[cur]!=cor[viz]) liga(cur, viz); } } } n*=m; bfs(); printf("%d\n", respf); }

Compilation message (stderr)

tracks.cpp: In function 'void bfs()':
tracks.cpp:39:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(ind<qu.size()) {
        ~~~^~~~~~~~~~
tracks.cpp:42:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if(marc[cur]==2) continue; marc[cur]=2; 
   ^~
tracks.cpp:42:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   if(marc[cur]==2) continue; marc[cur]=2; 
                              ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", c);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...