Submission #675784

#TimeUsernameProblemLanguageResultExecution timeMemory
675784NONTACTracks in the Snow (BOI13_tracks)C++11
2.19 / 100
1281 ms31784 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int n, m; char grid[4002][4002]; bool vis[4002][4002]; void bfs(int si, int sj, char c) { queue<ii> q; vis[si][sj] = true; q.push(ii(si, sj)); while(!q.empty()){ int ui = q.front().first, uj = q.front().second; q.pop(); for(int i = 0; i < 4; i++){ int vi = ui + dx[i], vj = uj + dy[i]; if(!vis[vi][vj]){ if(grid[vi][vj] == grid[ui][uj]){ vis[vi][vj] = true; q.push(ii(vi, vj)); } } } } } int main() { //freopen("test.in","r",stdin); //freopen("test.out","w",stdout); cin>>n>>m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) cin>>grid[i][j]; } int fox = 0, rab = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(grid[i][j] == 'F'){ if(!vis[i][j]){ fox++; bfs(i, j, 'F'); } } } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(grid[i][j] == 'R'){ if(!vis[i][j]){ rab++; bfs(i, j, 'R'); } } } } cout<<min(rab, fox) + 1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...