제출 #1136343

#제출 시각아이디문제언어결과실행 시간메모리
1136343footbelikeTracks in the Snow (BOI13_tracks)C++20
7.19 / 100
2097 ms47512 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int ans = 0, amount = 0; int n, m; char a; cin >> n >> m; char board[n][m]; bool board2[n][m]; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cin >> board[i][j]; if (board[i][j] != '.') amount++; board2[i][j] = 0; } } char moves = board[0][0]; if (moves == 'F') a = 'R'; if (moves == 'R') a = 'F'; if (moves == '.'){ cout << ans; return 0; } int r = 0; while (r != amount && ans != 5){ char moves = board[0][0]; if (moves == 'F') a = 'R'; if (moves == 'R') a = 'F'; queue <pair<int, int>> q; q.push({0, 0}); bool visited[n][m]; for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ visited[i][j] = 0; } } while (!q.empty()){ int x = q.front().first; int y = q.front().second; board[x][y] = a; if (board2[x][y] == 0) r++; board2[x][y] = 1; q.pop(); if (!visited[x][y]){ visited[x][y] = 1; if (x != 0 && !visited[x-1][y] && board[x-1][y] == moves) q.push({x-1, y}); if (x != n - 1 && !visited[x+1][y] && board[x+1][y] == moves) q.push({x+1, y}); if (y != 0 && !visited[x][y-1] && board[x][y-1] == moves) q.push({x, y-1}); if (y != m - 1 && !visited[x][y+1] && board[x][y+1] == moves) q.push({x, y+1}); } } board[0][0] = a; ans++; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...