Submission #1306160

#TimeUsernameProblemLanguageResultExecution timeMemory
1306160gaspadTracks in the Snow (BOI13_tracks)C++20
2.19 / 100
652 ms281356 KiB
#include <bits/stdc++.h> #define int long long using namespace std; typedef vector<int> vi; typedef pair<int, int> ii; int n, m; vector<vector<bool>> visited; vector<vector<char>> mtx; queue<ii> q; // dr, dc, mov tuple<int, int, char> moves[]{{1, 0, 'D'}, {-1, 0, 'U'}, {0, 1, 'R'}, {0, -1, 'L'}}; bool is_possible(ii pos){ auto [r, c] = pos; if(r < 0 || r >= n || c < 0 || c >= m) return false; return true; } int bfs(ii src){ int qtt = 1; char sy = mtx[src.first][src.second]; q.emplace(src); while(!q.empty()){ ii curr = q.front(); q.pop(); visited[curr.first][curr.second] = true; for(auto [dr, dc, mov] : moves){ int new_r = curr.first + dr; int new_c = curr.second + dc; if(is_possible({new_r, new_c})){ if(visited[new_r][new_c]) continue; if(mtx[new_r][new_c] == '.') continue; if(mtx[new_r][new_c] != sy) qtt = 2; visited[new_r][new_c] = true; q.emplace(new_r, new_c); } } } return qtt; } void solve(){ // int n, m; cin >> n >> m; vector<ii> cands; mtx.assign(n, vector<char>(m)); visited.assign(n, vector<bool>(m, false)); for(int i=0; i<n; i++){ for(int j=0; j<m; j++){ cin >> mtx[i][j]; if(mtx[i][j] == 'R' || mtx[i][j] == 'F'){ cands.emplace_back(i, j); } } } int ans = 0; for(auto [a, b] : cands){ if(!visited[a][b]){ ans += bfs({a, b}); } } cout << ans << "\n"; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...