제출 #368090

#제출 시각아이디문제언어결과실행 시간메모리
368090R3KTTracks in the Snow (BOI13_tracks)C++17
54.06 / 100
2094 ms72740 KiB
#include <iostream> #include <vector> #include <map> #include <cmath> #include <algorithm> #include <deque> #include <queue> #include <stack> #include <set> #include <string> #include <string.h> #include <array> #include <unordered_map> #include <unordered_set> #include <iomanip> using namespace std; typedef long long ll; const int MaxN = 4e3; int h, w; char arr[MaxN][MaxN]; bool visited[MaxN][MaxN]; queue<pair<int, int>> temp; bool dfs(char type) { queue<pair<int, int>> q; while (!temp.empty()) { q.push(temp.front()); temp.pop(); } int count=0; while (!q.empty()) { pair<int, int> cur = q.front(); q.pop(); if (cur.first < 0 || cur.second < 0 || cur.first >= h || cur.second >= w) continue; if (visited[cur.first][cur.second]) continue; if (arr[cur.first][cur.second] != type) { temp.push({cur.first, cur.second}); continue; } visited[cur.first][cur.second] = true; count++; q.push({cur.first+1, cur.second}); q.push({cur.first-1, cur.second}); q.push({cur.first, cur.second+1}); q.push({cur.first, cur.second-1}); } return count != 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for (int i=0; i<h; i++) { for (int j=0; j<w; j++) { cin >> arr[i][j]; } } bool fox = false; if (arr[0][0] == 'F') fox = true; temp.push({0,0}); int count=0; while (true) { char type = 'F'; if (!fox) type = 'R'; if (!dfs(type)) break; count++; fox = !fox; } cout << count; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...