Submission #471456

# Submission time Handle Problem Language Result Execution time Memory
471456 2021-09-09T11:51:49 Z huukhang Tracks in the Snow (BOI13_tracks) C++11
32.1875 / 100
34 ms 3140 KB
/*
						   Khangnh's code

"You can either experience the pain of discipline or the pain of regret. 
						The choice is yours."
*/

// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout);

#define ll long long
// #define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define eb emplace_back
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const double pi = acos(-1);
const double eps = 1e-9;

const int dx[] = {-1, 1, 0, 0},
		  dy[] = {0, 0, -1, 1};

int n, m;
char a[505][505];
int d[505][505];
int ans = 0;

bool inside(int x, int y) {
	if (x < 1 || x > n || y < 1 || y > m) return false;
	return true;
}

void bfs(pii s) {
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			d[i][j] = inf;

	deque<pii> dq;
	dq.pf(s);
	d[s.fi][s.se] = 1;

	while (!dq.empty()) {
		int x = dq.front().fi, y = dq.front().se;
		dq.pof();
		ans = max(ans, d[x][y]);

		for (int i = 0; i < 4; ++i) {
			int nx = x + dx[i], ny = y + dy[i];
			if (!inside(nx, ny)) continue;
			if (a[nx][ny] == '.') continue;

			bool w = a[x][y] != a[nx][ny];
			if (d[x][y] + w < d[nx][ny]) {
				d[nx][ny] = d[x][y] + w;
				(w ? dq.pb({nx, ny}) : dq.pf({nx, ny}));
			}
		}
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];

	bfs({1, 1});
	cout << ans;
}

signed main() {
	#ifdef LOCAL
		fileopen("input", "output");
		auto start = clock();
	#endif
	#ifndef LOCAL
//		fileopen("LAH", "LAH");
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int test = 1;
//	cin >> test;
	for (int tc = 1; tc <= test; ++tc) solve();
	#ifdef LOCAL
		auto end = clock();
		cout << "\n\nExecution time : " << double(end - start)/CLOCKS_PER_SEC << "[s]";
	#endif
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1788 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 12 ms 1840 KB Output is correct
5 Correct 3 ms 1092 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 3 ms 976 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 6 ms 1100 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 12 ms 1832 KB Output is correct
16 Correct 14 ms 1836 KB Output is correct
17 Correct 10 ms 1676 KB Output is correct
18 Correct 8 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 972 KB Execution killed with signal 11
2 Runtime error 11 ms 1680 KB Execution killed with signal 11
3 Runtime error 34 ms 3012 KB Execution killed with signal 11
4 Runtime error 17 ms 2056 KB Execution killed with signal 11
5 Runtime error 26 ms 2512 KB Execution killed with signal 11
6 Runtime error 32 ms 3100 KB Execution killed with signal 11
7 Runtime error 2 ms 1100 KB Execution killed with signal 11
8 Runtime error 1 ms 972 KB Execution killed with signal 11
9 Incorrect 2 ms 336 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Runtime error 2 ms 972 KB Execution killed with signal 11
12 Correct 1 ms 716 KB Output is correct
13 Runtime error 11 ms 1628 KB Execution killed with signal 11
14 Runtime error 9 ms 1608 KB Execution killed with signal 11
15 Runtime error 9 ms 1612 KB Execution killed with signal 11
16 Incorrect 11 ms 1844 KB Output isn't correct
17 Runtime error 17 ms 1996 KB Execution killed with signal 11
18 Runtime error 17 ms 2016 KB Execution killed with signal 11
19 Runtime error 18 ms 2044 KB Execution killed with signal 11
20 Runtime error 16 ms 2100 KB Execution killed with signal 11
21 Runtime error 30 ms 2496 KB Execution killed with signal 11
22 Runtime error 24 ms 2528 KB Execution killed with signal 11
23 Runtime error 27 ms 2508 KB Execution killed with signal 11
24 Runtime error 23 ms 2548 KB Execution killed with signal 11
25 Runtime error 31 ms 3012 KB Execution killed with signal 11
26 Runtime error 28 ms 2756 KB Execution killed with signal 11
27 Runtime error 32 ms 3080 KB Execution killed with signal 11
28 Runtime error 33 ms 3072 KB Execution killed with signal 11
29 Runtime error 32 ms 3076 KB Execution killed with signal 11
30 Runtime error 33 ms 3140 KB Execution killed with signal 11
31 Runtime error 25 ms 2636 KB Execution killed with signal 11
32 Runtime error 32 ms 3012 KB Execution killed with signal 11