제출 #770658

#제출 시각아이디문제언어결과실행 시간메모리
770658xCqliburTracks in the Snow (BOI13_tracks)C++17
30 / 100
2079 ms4532 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int mxH=505, mxW=505; int H, W; char grid[mxH][mxW], rChange[4]={0, 1, 0, -1}, cChange[4]={1, 0, -1, 0}; bool vis[mxH][mxW]; int floodfill(int r, int c, char curr) { int cnt=0; stack<pair<int, int>> frontier; frontier.push({r, c}); while(!frontier.empty()) { r=frontier.top().first; c=frontier.top().second; frontier.pop(); if(r<0||r>=H||c<0||c>=W||grid[r][c]!=curr||vis[r][c]) { continue; } ++cnt; vis[r][c]=1; grid[r][c]=(grid[r][c]=='F'?'R' : 'F'); for(int i=0; i<4; ++i) frontier.push({r+rChange[i], c+cChange[i]}); } return cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> H >> W; int tot=0; for(int i=0; i<H; ++i) { for(int j=0; j<W; ++j) { cin >> grid[i][j]; if(grid[i][j]!='.') ++tot; } } int ans=0; while(1) { memset(vis, 0, sizeof(vis)); if(tot==floodfill(0, 0, grid[0][0])) break; ++ans; } cout << ans+1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...