제출 #1026792

#제출 시각아이디문제언어결과실행 시간메모리
1026792vjudge1Tracks in the Snow (BOI13_tracks)C++17
0 / 100
889 ms91044 KiB
#include <bits/stdc++.h> using namespace std; int h, w; char m[4000][4000]; queue<pair<int, int> > q; int vis[4000][4000]; vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int main() { cin>>h>>w; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { cin>>m[h][w]; } } int res = 1; char animal = m[0][0]; bool finish = false; while(!finish) { q.push({0, 0}); while(q.size()) { int y = q.front().first; int x = q.front().second; q.pop(); finish = true; if(vis[y][x] == res || animal != m[y][x]) continue; vis[y][x] = res; m[y][x] = 'A'; for(auto d : dir) { int newY = y + d.first; int newX = x + d.second; if(newY >= 0 && newY < h && newX >= 0 && newX < w && vis[newY][newX] != res) if(m[y][x] == animal || m[y][x] == 'A') q.push({newY, newX}); } } res++; } cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...