Submission #777205

#TimeUsernameProblemLanguageResultExecution timeMemory
777205RonTheprogrammerTracks in the Snow (BOI13_tracks)C++17
Compilation error
0 ms0 KiB
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};

int n, m, depth[4000][4000], ans = 1;
string snow[4000];

bool inside(int x, int y) {
	return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}

int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> snow[i];

	deque<pair<int, int>> q;
	q.push_back({0, 0});
	depth[0][0] = 1;

	while (q.size()) {
		pair<int, int> c = q.front();
		q.pop_front();
		ans = max(ans, depth[c.first][c.second]);

		for (int i = 0; i < 4; i++) {
			int x = c.first + dx[i], y = c.second + dy[i];
			if (inside(x, y) && depth[x][y] == 0) {
				if (snow[x][y] == snow[c.first][c.second]) {
					depth[x][y] = depth[c.first][c.second];
					q.push_front({x, y});
				} else {
					depth[x][y] = depth[c.first][c.second] + 1;
					q.push_back({x, y});
				}
			}
		}
	}

	cout << ans;
	return 0;
}

Compilation message (stderr)

tracks.cpp:4:1: error: 'string' does not name a type
    4 | string snow[4000];
      | ^~~~~~
tracks.cpp: In function 'bool inside(int, int)':
tracks.cpp:7:48: error: 'snow' was not declared in this scope
    7 |  return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
      |                                                ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:11:2: error: 'iostream' has not been declared
   11 |  iostream::sync_with_stdio(false);
      |  ^~~~~~~~
tracks.cpp:12:2: error: 'cin' was not declared in this scope
   12 |  cin.tie(0);
      |  ^~~
tracks.cpp:15:37: error: 'snow' was not declared in this scope
   15 |  for (int i = 0; i < n; i++) cin >> snow[i];
      |                                     ^~~~
tracks.cpp:17:2: error: 'deque' was not declared in this scope
   17 |  deque<pair<int, int>> q;
      |  ^~~~~
tracks.cpp:17:8: error: 'pair' was not declared in this scope
   17 |  deque<pair<int, int>> q;
      |        ^~~~
tracks.cpp:17:13: error: expected primary-expression before 'int'
   17 |  deque<pair<int, int>> q;
      |             ^~~
tracks.cpp:18:2: error: 'q' was not declared in this scope
   18 |  q.push_back({0, 0});
      |  ^
tracks.cpp:22:8: error: expected primary-expression before 'int'
   22 |   pair<int, int> c = q.front();
      |        ^~~
tracks.cpp:24:24: error: 'c' was not declared in this scope
   24 |   ans = max(ans, depth[c.first][c.second]);
      |                        ^
tracks.cpp:24:9: error: 'max' was not declared in this scope
   24 |   ans = max(ans, depth[c.first][c.second]);
      |         ^~~
tracks.cpp:28:18: error: 'y' was not declared in this scope
   28 |    if (inside(x, y) && depth[x][y] == 0) {
      |                  ^
tracks.cpp:29:9: error: 'snow' was not declared in this scope
   29 |     if (snow[x][y] == snow[c.first][c.second]) {
      |         ^~~~
tracks.cpp:40:2: error: 'cout' was not declared in this scope
   40 |  cout << ans;
      |  ^~~~