Submission #101578

#TimeUsernameProblemLanguageResultExecution timeMemory
101578dantoh000Tracks in the Snow (BOI13_tracks)C++14
100 / 100
1742 ms113192 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1}; int main(){ int h,w; scanf("%d%d",&h,&w); char grid[h][w]; int nonempty = 0; for (int i = 0; i < h; i++){ for (int j = 0; j < w; j++){ scanf(" %c",&grid[i][j]); if (grid[i][j] != '.') nonempty++; } } int num = 0; int vis[h][w]; int ans = 1; char a = grid[0][0]; char b = a^'F'^'R'; memset(vis,0,sizeof(vis)); deque<ii> q; q.push_back(ii(0,0)); vis[0][0] = 1; while(q.size()){ ii cur = q.front(); q.pop_front(); int x = cur.first, y = cur.second; for (int k = 0; k < 4; k++){ int nx = x + dx[k], ny = y + dy[k]; if (nx >= 0 && nx < h && ny >= 0 && ny < w && vis[nx][ny] == 0 && grid[nx][ny] != '.'){ if (grid[nx][ny] == grid[x][y]){ vis[nx][ny] = vis[x][y]; q.push_front(ii(nx,ny)); } else{ vis[nx][ny] = vis[x][y]+1; q.push_back(ii(nx,ny)); } ans = max(ans,vis[nx][ny]); //printf("%d %d %d\n",vis[nx][ny],nx,ny); } } } printf("%d",ans); }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:16:9: warning: unused variable 'num' [-Wunused-variable]
     int num = 0;
         ^~~
tracks.cpp:20:10: warning: unused variable 'b' [-Wunused-variable]
     char b = a^'F'^'R';
          ^
tracks.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&h,&w);
     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&grid[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...