Submission #715911

#TimeUsernameProblemLanguageResultExecution timeMemory
715911FarbodTracks in the Snow (BOI13_tracks)C++17
57.81 / 100
2110 ms1038620 KiB
/* * In the name of God * * Author: Farbod Doost * Last Modified: Tue, 28 Mar 2023 (15:29:19) * */ #include <bits/stdc++.h> using namespace std; #define int short int const int N = 4005; int n, m; bool vis[N][N]; char a[N][N]; int T = 0; deque <pair <int, int>> vec; bool t = 0; int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; bool f(char a, char b) { if (t) return a != b; return a == b; } bool val(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '.' && !vis[i][j] && f(a[i][j], a[0][0]); } void dfs(int x = 0, int y = 0) { vis[x][y] = 1, vec.push_back({x, y}); for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (val(nx, ny)) dfs(nx, ny); } return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; dfs(); while (vec.size()) { int tmp = vec.size(); t = 1 - t; for (int j = 0; j < vec.size(); j++) { int x = vec[j].first, y = vec[j].second; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (val(nx, ny)) vec.push_back({nx, ny}), vis[nx][ny] = 1; } } while (tmp--) vec.pop_front(); T++; } cout << T; return 0; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:65:27: warning: comparison of integer expressions of different signedness: 'short int' and 'std::deque<std::pair<short int, short int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int j = 0; j < vec.size(); j++) {
      |                         ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...