답안 #888477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888477 2023-12-17T14:04:22 Z bashNewbie Tracks in the Snow (BOI13_tracks) C++17
69.375 / 100
2000 ms 344556 KB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

#define fast_io ios::sync_with_stdio(0), cin.tie(0)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back

int main() {
	fast_io;

	vvi adj = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

	int n, m; cin >> n >> m;
	vs s(n); for(auto &t: s) cin >> t;

	auto in = [&] (vi v) {
		return -1 < v[0] && v[0] < n && -1 < v[1] && v[1] < m;
	};
	auto f = [&] (vi v) {
		return s[v[0]][v[1]];
	};
	auto g = [&] (vi v) {
		return v[0]*m+v[1];
	};
	auto bad = [&] (vi v) {
		return f(v) == '.';
	};
	auto same = [&] (vi v, vi w) {
		return f(v) == f(w);
	};

	queue<vi> q, nq; vi vis(n*m); int ret = 0;
	q.push({0, 0}), vis[g({0, 0})] = 1;
	while(!q.empty()) {
		ret++;
		while(!q.empty()) {
			vi v = q.front(); q.pop(), nq.push(v);
			for(auto c: adj) {
				vi w = {v[0]+c[0], v[1]+c[1]};
				if(!in(w) || vis[g(w)] || bad(w) || !same(v, w)) continue;
				q.push(w), vis[g(w)] = 1;
			}
		}
		while(!nq.empty()) {
			vi v = nq.front(); nq.pop();
			for(auto c: adj) {
				vi w = {v[0]+c[0], v[1]+c[1]};
				if(!in(w) || vis[g(w)] || bad(w)) continue;
				q.push(w), vis[g(w)] = 1;
			}
		}
	}
	cout << ret << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 114 ms 5200 KB Output is correct
5 Correct 21 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 21 ms 604 KB Output is correct
11 Correct 28 ms 1624 KB Output is correct
12 Correct 62 ms 1116 KB Output is correct
13 Correct 17 ms 860 KB Output is correct
14 Correct 22 ms 860 KB Output is correct
15 Correct 145 ms 1884 KB Output is correct
16 Correct 174 ms 2392 KB Output is correct
17 Correct 87 ms 1628 KB Output is correct
18 Correct 106 ms 5184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 856 KB Output is correct
2 Correct 528 ms 8284 KB Output is correct
3 Execution timed out 2037 ms 81232 KB Time limit exceeded
4 Correct 505 ms 19292 KB Output is correct
5 Execution timed out 2041 ms 45656 KB Time limit exceeded
6 Execution timed out 2057 ms 239352 KB Time limit exceeded
7 Correct 10 ms 860 KB Output is correct
8 Correct 12 ms 860 KB Output is correct
9 Correct 25 ms 1116 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 10 ms 596 KB Output is correct
13 Correct 558 ms 8284 KB Output is correct
14 Correct 343 ms 4952 KB Output is correct
15 Correct 229 ms 5468 KB Output is correct
16 Correct 288 ms 3860 KB Output is correct
17 Correct 1355 ms 21024 KB Output is correct
18 Correct 933 ms 20572 KB Output is correct
19 Correct 520 ms 19288 KB Output is correct
20 Correct 747 ms 17756 KB Output is correct
21 Correct 1835 ms 47192 KB Output is correct
22 Execution timed out 2075 ms 45660 KB Time limit exceeded
23 Execution timed out 2040 ms 39768 KB Time limit exceeded
24 Execution timed out 2060 ms 46172 KB Time limit exceeded
25 Execution timed out 2048 ms 81232 KB Time limit exceeded
26 Execution timed out 2058 ms 327356 KB Time limit exceeded
27 Execution timed out 2052 ms 344556 KB Time limit exceeded
28 Execution timed out 2062 ms 239568 KB Time limit exceeded
29 Execution timed out 2065 ms 268552 KB Time limit exceeded
30 Execution timed out 2051 ms 296656 KB Time limit exceeded
31 Execution timed out 2017 ms 57484 KB Time limit exceeded
32 Execution timed out 2063 ms 343364 KB Time limit exceeded