제출 #1178772

#제출 시각아이디문제언어결과실행 시간메모리
1178772petezaTracks in the Snow (BOI13_tracks)C++20
100 / 100
859 ms106564 KiB
#include <bits/stdc++.h> using namespace std; int n, m; bool vis[4005][4005]; char mp[4005][4005]; queue<pair<int, int>> q[256]; int dirx[4] = {0, 0, 1, -1}, diry[4] = {1, -1, 0, 0}; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> m; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) cin >> mp[i][j]; } assert(mp[0][0] != '.'); char st = mp[0][0]; q[st].emplace(0, 0); int cnt = 0; while(1) { bool updq = 0; while(!q[st].empty()) { auto e = q[st].front(); q[st].pop(); if(vis[e.first][e.second]) continue; vis[e.first][e.second] = 1; updq = 1; for(int i=0;i<4;i++) { int ni = e.first + dirx[i], nj = e.second + diry[i]; if(ni >= 0 && nj >= 0 && ni < n && nj < m) { q[mp[ni][nj]].emplace(ni, nj); } } } if(!updq) break; cnt++; if(st == 'F') st = 'R' ; else st = 'F'; } cout << cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...