Submission #76040

#TimeUsernameProblemLanguageResultExecution timeMemory
76040tmwilliamlin168Tracks in the Snow (BOI13_tracks)C++14
100 / 100
1204 ms901464 KiB
#include <bits/stdc++.h> using namespace std; const int mxN=4e3; int n, m, ans, nb[4][2]={{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; string g[mxN]; vector<array<int, 2>> tp[2]; __attribute__((always_inline)) bool a(int i, int j) { return i>=0&&i<n&&j>=0&&j<m&&g[i][j]!='.'; } void dfs(int i, int j) { char pc=g[i][j]; g[i][j]='.'; for(int k=0; k<4; ++k) { int ni=i+nb[k][0], nj=j+nb[k][1]; if(!a(ni, nj)) continue; if(g[ni][nj]==pc) dfs(ni, nj); else tp[ans&1^1].push_back({ni, nj}); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i=0; i<n; ++i) cin >> g[i]; tp[0].push_back({0, 0}); for(; tp[ans&1].size(); ++ans) { for(array<int, 2> u : tp[ans&1]) if(a(u[0], u[1])) dfs(u[0], u[1]); tp[ans&1].clear(); } cout << ans; }

Compilation message (stderr)

tracks.cpp: In function 'void dfs(int, int)':
tracks.cpp:23:10: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    tp[ans&1^1].push_back({ni, nj});
       ~~~^~
tracks.cpp: At global scope:
tracks.cpp:9:37: warning: always_inline function might not be inlinable [-Wattributes]
 __attribute__((always_inline)) bool a(int i, int j) {
                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...