Submission #855409

# Submission time Handle Problem Language Result Execution time Memory
855409 2023-10-01T08:29:29 Z dayalk Tracks in the Snow (BOI13_tracks) C++17
19.7917 / 100
847 ms 121928 KB
#include <bits/stdc++.h>
#define mod 1000000007
#define init(arr, val) memset(arr, val, sizeof(arr))
#define fr(a,b) for(ll i = a; i < b; i++)
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loopr(i, a, b) for (ll i = a; i >= b; i--)
#define loops(i, a, b, step) for (ll i = a; i < b; i += step)
#define looprs(i, a, b, step) for (ll i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define pll pair<long long, long long>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define fast_io                       \
	ios_base::sync_with_stdio(false); \
	cin.tie();                        \
	cout.tie()
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define prDouble(x) cout << fixed << setprecision(10) << x
#define all(a) a.begin(), a.end()
#define ld long double
#define inf (1LL<<60)
using namespace std;
const ll maxn = 2e5 + 1;
const double pi = acos(-1);

vector<pii> dir = { {1,0}, {0,1}, {0, -1}, {-1, 0} };

int main() {
	fast_io;
	int tests = 1;
	// cin >> tests;
	for (int test_case = 1; test_case <= tests; test_case++) {
		int h, w; cin >> h >> w;
		char a[h][w];
		fr(0, h) {
			loop(j, 0, w) cin >> a[i][j];
		}
		vector<int> d(h * w, 1e9);
		d[0] = 1;
		deque<pair<int, int>> q;
		q.push_back(make_pair(0, 0));
		int res = 0;
		while (!q.empty()) {
			auto cur = q.front();
			int curf = cur.first;
			int curs = cur.second;
			q.pop_front();
			auto dis = d[curf * w + curs];
			for (auto i : dir) {
				// pii j = cur + i;
				int jf = curf + i.first;
				int js = curs + i.second;
				if (jf < 0) continue;
				if (jf >= h) continue;
				if (js < 0) continue;
				if (js >= w) continue;

				int e = 0;
				// if (a[curf][curs] != '.') {
				e = (a[curf][curs] != a[jf][js]);
				// }
				if (dis + e < d[jf * w + js]) {
					d[jf * w + js] = dis + e;
					if (e == 0) q.push_front({ jf,js });
					else q.push_back({ jf,js });
				}
			}
		}
		fr(0, h * w) {
			if (a[i / w][i % w]) res = max(res, d[i]);
		}
		cout << res << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1624 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Correct 6 ms 1372 KB Output is correct
5 Incorrect 4 ms 860 KB Output isn't correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 1 ms 348 KB Output isn't correct
10 Incorrect 3 ms 860 KB Output isn't correct
11 Correct 2 ms 600 KB Output is correct
12 Incorrect 4 ms 860 KB Output isn't correct
13 Incorrect 4 ms 1112 KB Output isn't correct
14 Incorrect 4 ms 860 KB Output isn't correct
15 Incorrect 11 ms 2104 KB Output isn't correct
16 Incorrect 11 ms 1624 KB Output isn't correct
17 Incorrect 11 ms 1628 KB Output isn't correct
18 Correct 9 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Incorrect 59 ms 11592 KB Output isn't correct
3 Incorrect 594 ms 121928 KB Output isn't correct
4 Incorrect 139 ms 19284 KB Output isn't correct
5 Incorrect 327 ms 81620 KB Output isn't correct
6 Correct 673 ms 93268 KB Output is correct
7 Incorrect 2 ms 600 KB Output isn't correct
8 Incorrect 2 ms 604 KB Output isn't correct
9 Incorrect 2 ms 860 KB Output isn't correct
10 Incorrect 1 ms 604 KB Output isn't correct
11 Incorrect 2 ms 752 KB Output isn't correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Incorrect 57 ms 11788 KB Output isn't correct
14 Incorrect 37 ms 7000 KB Output isn't correct
15 Incorrect 37 ms 7508 KB Output isn't correct
16 Incorrect 24 ms 4956 KB Output isn't correct
17 Incorrect 154 ms 29868 KB Output isn't correct
18 Incorrect 175 ms 29248 KB Output isn't correct
19 Incorrect 156 ms 19280 KB Output isn't correct
20 Incorrect 121 ms 26308 KB Output isn't correct
21 Incorrect 330 ms 68648 KB Output isn't correct
22 Incorrect 317 ms 81492 KB Output isn't correct
23 Incorrect 298 ms 57300 KB Output isn't correct
24 Incorrect 311 ms 69884 KB Output isn't correct
25 Incorrect 847 ms 116440 KB Output isn't correct
26 Correct 424 ms 110468 KB Output is correct
27 Correct 605 ms 121816 KB Output is correct
28 Correct 703 ms 93288 KB Output is correct
29 Correct 760 ms 90404 KB Output is correct
30 Correct 697 ms 96760 KB Output is correct
31 Incorrect 480 ms 51016 KB Output isn't correct
32 Incorrect 631 ms 101012 KB Output isn't correct