Submission #1229417

#TimeUsernameProblemLanguageResultExecution timeMemory
1229417chikien2009Tracks in the Snow (BOI13_tracks)C++20
2.19 / 100
665 ms794780 KiB
#include <bits/stdc++.h> using namespace std; void setup() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int dx[4] = {0, 0, -1, 1}; int dy[4] = {1, -1, 0, 0}; int h, w, a, b; string s[4000]; bool check[4000][4000]; inline void BFS(int x, int y, char c) { check[x][y] = true; for (int i = 0; i < 4; ++i) { if (0 <= x + dx[i] && x + dx[i] < h && 0 <= y + dy[i] && y + dy[i] < w && s[x + dx[i]][y + dy[i]] == c && !check[x + dx[i]][y + dy[i]]) { BFS(x + dx[i], y + dy[i], c); } } } int main() { setup(); cin >> h >> w; for (int i = 0; i < h; ++i) { cin >> s[i]; } for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (!check[i][j] && s[i][j] != '.') { if (s[i][j] == 'R') { BFS(i, j, 'R'); a++; } else { BFS(i, j, 'F'); b++; } } } } if (s[0][0] == 'R') { cout << (a <= 1 ? 1 : 2) + (b > 0) << "\n"; } else { cout << (b <= 1 ? 1 : 2) + (a > 0) << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...