Submission #96948

#TimeUsernameProblemLanguageResultExecution timeMemory
96948dalgerokTracks in the Snow (BOI13_tracks)C++14
100 / 100
807 ms94004 KiB
#include<bits/stdc++.h> using namespace std; const int N = 4001, INF = 2e9, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; int n, m, d[N][N]; char a[N][N]; inline bool check(int x, int y){ return 1 <= x && x <= n && 1 <= y && y <= m; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> a[i] + 1; for(int j = 1; j <= m; j++){ d[i][j] = INF; } } deque < pair < short, short > > q; q.push_back(make_pair(1, 1)); d[1][1] = 1; while(!q.empty()){ int x = q.front().first, y = q.front().second; q.pop_front(); for(int i = 0; i < 4; i++){ int xx = x + dx[i], yy = y + dy[i]; if(check(xx, yy) && a[xx][yy] != '.'){ int val = d[x][y] + (a[x][y] != a[xx][yy]); if(d[xx][yy] > val){ d[xx][yy] = val; if(a[x][y] == a[xx][yy]){ q.push_front(make_pair(xx, yy)); } else{ q.push_back(make_pair(xx, yy)); } } } } } int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(a[i][j] != '.'){ ans = max(ans, d[i][j]); } } } cout << ans << "\n"; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin >> a[i] + 1;
                ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...