제출 #1001237

#제출 시각아이디문제언어결과실행 시간메모리
1001237vjudge3Tracks in the Snow (BOI13_tracks)C++17
97.81 / 100
1292 ms1048576 KiB
#include <bits/stdc++.h>
using namespace std;

char g[4005][4005];
bitset<4005> vis[4005];
vector<pair<short, short>> cur;
int h, w, dep = 1;
const int dr[4] = {0, 1, 0, -1}, dc[4] = {1, 0, -1, 0};

void dfs (int r, int c, char ch) {
	if (!vis[r][c]) cur.push_back({r, c});
	vis[r][c] = true;
	for (int k = 0; k < 4; k++) {
		int rv = r + dr[k], cv = c + dc[k];
		if (rv >= 1 && rv <= h && cv >= 1 && cv <= w && !vis[rv][cv] && g[rv][cv] == ch) dfs(rv, cv, ch);
	}
}

int main () {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> g[i][j];
	dfs(1, 1, g[1][1]);
	while (true) {
		dep++;
		vector<pair<short, short>> last;
		last.swap(cur);
		for (auto& [r, c] : last) dfs(r, c, "RF"[(dep & 1) ^ (g[1][1] == 'R')]);
		last.clear();
		if (cur.empty()) {
			cout << dep-1 << '\n';
			return 0;
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...