# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012941 | 2024-07-02T22:35:44 Z | parentoni | Tracks in the Snow (BOI13_tracks) | C++17 | 402 ms | 235728 KB |
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define print(x) for (auto el: x) cout << el << " "; cout << '\n' using ll = long long; using llb = long double; using vl = vector<ll>; using pll = pair<ll,ll>; // functions void setIO(string s) {freopen((s + ".in").c_str(), "r", stdin);freopen((s + ".out").c_str(), "w", stdout);} void yes() { cout<<"YES\n"; } void no() { cout<<"NO\n"; } // geometry const double PI = 3.14159265358979323846; double DEG_to_RAD (double d) {return d*PI/180.0;} double RAD_to_DEG (double r) {return r*180.0/ PI;} // values const ll INF = 1e18; const ll MOD = 1000000007; const ll MAX_N = 4000; ll h, w; ll dx[4] = {1,-1,0,0}; ll dy[4] = {0,0,1,-1}; string board[4000]; ll depth[4000][4000]; deque<pll> q; bool inside(ll x, ll y) { return (x >= 0 && x < h && y >=0 && y < w && board[x][y] != '.'); } ll bfs() { ll ans = 1; depth[0][0] = 1; q.push_back({0,0}); while(q.size()) { pll a = q.front(); q.pop_front(); ans = max(ans, depth[a.first][a.second]); for (int i=0;i<4;i++) { ll x = a.first + dx[i], y = a.second +dy[i]; if (!depth[x][y] && inside(x, y)) { if (board[a.first][a.second] != board[x][y]) { q.push_back({x,y}); depth[x][y] = depth[a.first][a.second] + 1; } else { q.push_front({x,y}); depth[x][y] = depth[a.first][a.second]; } } } } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w; for (int i=0;i<h;i++) { cin >> board[i]; } cout << bfs() << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4956 KB | Output is correct |
2 | Correct | 0 ms | 604 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 4 ms | 4472 KB | Output is correct |
5 | Correct | 2 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 592 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 1 ms | 860 KB | Output is correct |
10 | Correct | 2 ms | 1880 KB | Output is correct |
11 | Correct | 2 ms | 1884 KB | Output is correct |
12 | Correct | 4 ms | 2652 KB | Output is correct |
13 | Correct | 2 ms | 2396 KB | Output is correct |
14 | Correct | 2 ms | 2396 KB | Output is correct |
15 | Correct | 7 ms | 4616 KB | Output is correct |
16 | Correct | 9 ms | 4956 KB | Output is correct |
17 | Correct | 7 ms | 4700 KB | Output is correct |
18 | Correct | 4 ms | 4444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 15964 KB | Output is correct |
2 | Correct | 27 ms | 15440 KB | Output is correct |
3 | Correct | 126 ms | 93420 KB | Output is correct |
4 | Correct | 50 ms | 43092 KB | Output is correct |
5 | Correct | 124 ms | 69320 KB | Output is correct |
6 | Correct | 402 ms | 186116 KB | Output is correct |
7 | Correct | 7 ms | 16732 KB | Output is correct |
8 | Correct | 6 ms | 15964 KB | Output is correct |
9 | Correct | 1 ms | 1116 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 7 ms | 16476 KB | Output is correct |
12 | Correct | 1 ms | 1372 KB | Output is correct |
13 | Correct | 29 ms | 15188 KB | Output is correct |
14 | Correct | 18 ms | 10076 KB | Output is correct |
15 | Correct | 13 ms | 14172 KB | Output is correct |
16 | Correct | 13 ms | 6464 KB | Output is correct |
17 | Correct | 68 ms | 32856 KB | Output is correct |
18 | Correct | 54 ms | 47692 KB | Output is correct |
19 | Correct | 47 ms | 43088 KB | Output is correct |
20 | Correct | 35 ms | 27220 KB | Output is correct |
21 | Correct | 87 ms | 60968 KB | Output is correct |
22 | Correct | 124 ms | 69284 KB | Output is correct |
23 | Correct | 131 ms | 56376 KB | Output is correct |
24 | Correct | 91 ms | 59500 KB | Output is correct |
25 | Correct | 224 ms | 158880 KB | Output is correct |
26 | Correct | 213 ms | 235728 KB | Output is correct |
27 | Correct | 266 ms | 212292 KB | Output is correct |
28 | Correct | 351 ms | 185936 KB | Output is correct |
29 | Correct | 374 ms | 183004 KB | Output is correct |
30 | Correct | 323 ms | 191640 KB | Output is correct |
31 | Correct | 312 ms | 115352 KB | Output is correct |
32 | Correct | 237 ms | 183464 KB | Output is correct |