제출 #1302631

#제출 시각아이디문제언어결과실행 시간메모리
1302631lunarechoTracks in the Snow (BOI13_tracks)C++20
2.19 / 100
391 ms18440 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int dx[] = {0, 0, 1, -1}; int dy[] = {-1, 1, 0, 0}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin>>n>>m; vector<vector<char>> grid(n, vector<char>(m)); for(int i=0;i<n;++i) { for(int j=0;j<m;++j) { cin>>grid[i][j]; } } vector<vector<bool>> vis(n, vector<bool>(m, false)); int ans = 0; for(int i=0;i<n;++i) { for(int j=0;j<m;++j) { if(!vis[i][j] && grid[i][j] != '.') { queue<pair<int, int>> q; bool f = grid[i][j] == 'F', s = !f; q.push({i, j}); vis[i][j] = true; while(!q.empty()) { auto it = q.front(); q.pop(); for(int k=0;k<4;++k) { int x = it.first + dx[k], y = it.second + dy[k]; if(x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] && grid[x][y] != '.') { q.push({x, y}); vis[x][y] = true; if(grid[x][y] == 'F') { f = true; } else { s = true; } } } } if(f && s) { ans += 2; } else { ++ans; } } } } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...