제출 #1235532

#제출 시각아이디문제언어결과실행 시간메모리
1235532jiayiiyaijTracks in the Snow (BOI13_tracks)C++20
51.88 / 100
2095 ms18424 KiB
#include <iostream> #include <vector> #include<queue> #include <algorithm> using namespace std; int main() { int H, W; cin >> H >> W; cin.ignore(); vector<vector<char>> mapp(H, vector<char>(W)); for (int i=0; i<H; i++) { string line; getline(cin, line); for (int j=0; j<W; j++) { mapp[i][j] = line[j]; } } vector<char> ani(2, '.'); if (mapp[0][0] == 'R') ani = {'R', 'F'}; else ani = {'F', 'R'}; int dirs[4][2] = { {0,1}, {1,0}, {0,-1}, {-1,0} }; int count = 0; bool flag = false; while(true) { for (char a : ani) { flag = false; vector<vector<bool>> vis(H, vector<bool>(W, false)); vis[0][0] = true; queue<pair<int, int>> q; q.push({0,0}); while (!q.empty()) { int r = q.front().first; int c = q.front().second; q.pop(); for (int i = 0; i < 4; i++) { int rr = r + dirs[i][0]; int cc = c + dirs[i][1]; if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue; if (vis[rr][cc]) continue; if (mapp[rr][cc] == a || mapp[rr][cc] == '#') { vis[rr][cc] = true; if (mapp[rr][cc] == a) { flag = true; mapp[rr][cc] = '#'; } q.push({rr, cc}); } } } if (not flag) break; count += 1; } if (not flag) break; } cout << count; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...