Submission #652707

# Submission time Handle Problem Language Result Execution time Memory
652707 2022-10-24T01:31:00 Z chanhchuong123 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
783 ms 152728 KB
#include <bits/stdc++.h>
using namespace std;
#define task "C"
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
  if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
  if (a < b) {a = b; return true;} return false;
}

const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};
const int N = 4004;
int n, m;
int ans;
int d[N][N];
char a[N][N];
bool vis[N][N];

main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  if (fopen(task".inp","r")) {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  memset(d, 0x3f, sizeof(d));
  deque<pair<int, int>> dq;
  dq.push_back({1, 1});
  d[1][1] = 1;
  while (dq.size()) {
    auto [x, y] = dq.front();
    dq.pop_front();
    if (vis[x][y]) continue;
    vis[x][y] = 1; maxi(ans, d[x][y]);
    for (int i = 0; i < 4; i++) {
      int u = x + dx[i], v = y + dy[i];
      if (u < 1 || u > n) continue;
      if (v < 1 || v > m) continue;
      if (a[u][v] == '.') continue;
      int w = a[u][v] != a[x][y];
      if (mini(d[u][v], d[x][y] + w)) {
        if (w) dq.push_back({u, v});
        else dq.push_front({u, v});
      }
    }
  }
  cout << ans;
}

Compilation message

tracks.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main() {
      | ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:43:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |     auto [x, y] = dq.front();
      |          ^
tracks.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 67288 KB Output is correct
2 Correct 23 ms 63164 KB Output is correct
3 Correct 25 ms 63432 KB Output is correct
4 Correct 32 ms 67212 KB Output is correct
5 Correct 27 ms 65332 KB Output is correct
6 Correct 24 ms 63180 KB Output is correct
7 Correct 24 ms 63448 KB Output is correct
8 Correct 24 ms 63476 KB Output is correct
9 Correct 24 ms 63820 KB Output is correct
10 Correct 27 ms 64996 KB Output is correct
11 Correct 25 ms 64608 KB Output is correct
12 Correct 29 ms 65376 KB Output is correct
13 Correct 28 ms 65364 KB Output is correct
14 Correct 27 ms 65360 KB Output is correct
15 Correct 39 ms 67208 KB Output is correct
16 Correct 37 ms 67144 KB Output is correct
17 Correct 35 ms 67052 KB Output is correct
18 Correct 32 ms 67240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 93004 KB Output is correct
2 Correct 73 ms 74404 KB Output is correct
3 Correct 350 ms 110120 KB Output is correct
4 Correct 112 ms 81448 KB Output is correct
5 Correct 250 ms 95304 KB Output is correct
6 Correct 783 ms 125228 KB Output is correct
7 Correct 38 ms 94428 KB Output is correct
8 Correct 38 ms 93024 KB Output is correct
9 Correct 28 ms 63188 KB Output is correct
10 Correct 25 ms 63060 KB Output is correct
11 Correct 38 ms 93740 KB Output is correct
12 Correct 26 ms 64224 KB Output is correct
13 Correct 75 ms 74320 KB Output is correct
14 Correct 54 ms 71008 KB Output is correct
15 Correct 53 ms 71872 KB Output is correct
16 Correct 45 ms 66768 KB Output is correct
17 Correct 153 ms 82796 KB Output is correct
18 Correct 136 ms 82568 KB Output is correct
19 Correct 114 ms 81420 KB Output is correct
20 Correct 101 ms 80160 KB Output is correct
21 Correct 223 ms 96572 KB Output is correct
22 Correct 261 ms 95264 KB Output is correct
23 Correct 279 ms 90268 KB Output is correct
24 Correct 225 ms 96332 KB Output is correct
25 Correct 528 ms 110112 KB Output is correct
26 Correct 490 ms 152728 KB Output is correct
27 Correct 683 ms 150764 KB Output is correct
28 Correct 771 ms 125256 KB Output is correct
29 Correct 767 ms 122268 KB Output is correct
30 Correct 721 ms 126420 KB Output is correct
31 Correct 579 ms 98600 KB Output is correct
32 Correct 608 ms 133000 KB Output is correct