Submission #717013

#TimeUsernameProblemLanguageResultExecution timeMemory
717013geometry216Tracks in the Snow (BOI13_tracks)C++17
2.19 / 100
1290 ms411320 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int H, W; char grid[4000][4000]; bool visited[4000][4000]; void ff(int r, int c, char col){ if(r<0 || r>=H || c<0 || c>=W || visited[r][c] || grid[r][c]!=col) return; visited[r][c] = true; ff(r+1, c, col); ff(r, c+1, col); ff(r-1, c, col); ff(r, c-1, col); } int main() { //# of F connected componetntes + 1 or # of R compoentns + 1 cin >> H >> W; for (int r=0; r<H; r++){ for (int c=0; c<W; c++){ cin >> grid[r][c]; } } vector<int> ccs; ccs.push_back(0); ccs.push_back(0); for (int r=0; r<H; r++){ for (int c=0; c<W; c++){ if(!visited[r][c] && grid[r][c]!='.'){ ff(r, c, grid[r][c]); if(grid[r][c]=='R') ccs[0]++; else ccs[1]++; } } } cout << min(ccs[0], ccs[1])+1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...