Submission #770997

# Submission time Handle Problem Language Result Execution time Memory
770997 2023-07-02T10:12:26 Z ind1v Mecho (IOI09_mecho) C++11
38 / 100
149 ms 7548 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 805;
const int dI[4] = {-1, 0, +1, 0};
const int dJ[4] = {0, +1, 0, -1};

int n, s;
char a[N][N];
int d[N][N], f[N][N];
bool can[N][N];
int mx, my, dx, dy;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  memset(d, 0x3f, sizeof(d));
  memset(f, 0x3f, sizeof(f));
  queue<pair<int, int>> q;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'H') {
        d[i][j] = 0;
        q.push({i, j});
      } else if (a[i][j] == 'M') {
        mx = i;
        my = j;
      } else if (a[i][j] == 'D') {
        dx = i;
        dy = j;
      }
    }
  }
  while (!q.empty()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();
    for (int dir = 0; dir < 4; dir++) {
      int nx = x + dI[dir];
      int ny = y + dJ[dir];
      if (1 <= nx && nx <= n && 1 <= ny && ny <= n && a[nx][ny] != 'D' && a[nx][ny] != 'T' && d[nx][ny] > d[x][y] + 1) {
        d[nx][ny] = d[x][y] + 1;
        q.push({nx, ny});
      }
    }
  }
  int l = 0, r = n * n, ans = -1;
  while (l <= r) {
    int m = l + r >> 1;
    memset(f, 0x3f, sizeof(f));
    memset(can, false, sizeof(can));
    queue<pair<int, int>> q;
    if (m <= d[mx][my]) {
      f[mx][my] = s;
      can[mx][my] = true;
      q.push({mx, my});
    }
    while (!q.empty()) {
      int x, y;
      tie(x, y) = q.front();
      q.pop();
      for (int dir = 0; dir < 4; dir++) {
        int nx = x + dI[dir];
        int ny = y + dJ[dir];
        if (1 <= nx && nx <= n && 1 <= ny && ny <= n && a[nx][ny] != 'T' && f[nx][ny] > f[x][y] + 1 && f[x][y] / s + m <= d[nx][ny] && !can[nx][ny]) {
          f[nx][ny] = f[x][y] + 1;
          can[nx][ny] = true;
          q.push({nx, ny});
        }
      }
    }
    if (can[dx][dy]) {
      ans = m;
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  cout << ans;
  return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:52:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int m = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5972 KB Output isn't correct
2 Incorrect 3 ms 5956 KB Output isn't correct
3 Incorrect 3 ms 5960 KB Output isn't correct
4 Incorrect 3 ms 5972 KB Output isn't correct
5 Correct 3 ms 5960 KB Output is correct
6 Correct 3 ms 5972 KB Output is correct
7 Correct 65 ms 7344 KB Output is correct
8 Incorrect 3 ms 5972 KB Output isn't correct
9 Correct 3 ms 5972 KB Output is correct
10 Correct 3 ms 5972 KB Output is correct
11 Correct 3 ms 5972 KB Output is correct
12 Incorrect 3 ms 5972 KB Output isn't correct
13 Incorrect 4 ms 5972 KB Output isn't correct
14 Correct 3 ms 5972 KB Output is correct
15 Incorrect 3 ms 5972 KB Output isn't correct
16 Correct 3 ms 5956 KB Output is correct
17 Incorrect 3 ms 5972 KB Output isn't correct
18 Correct 3 ms 5960 KB Output is correct
19 Incorrect 3 ms 5960 KB Output isn't correct
20 Correct 3 ms 5972 KB Output is correct
21 Incorrect 3 ms 5972 KB Output isn't correct
22 Correct 3 ms 5972 KB Output is correct
23 Incorrect 3 ms 5972 KB Output isn't correct
24 Correct 3 ms 5960 KB Output is correct
25 Incorrect 3 ms 5972 KB Output isn't correct
26 Correct 3 ms 6084 KB Output is correct
27 Incorrect 3 ms 6100 KB Output isn't correct
28 Correct 3 ms 5972 KB Output is correct
29 Incorrect 3 ms 6088 KB Output isn't correct
30 Correct 3 ms 6100 KB Output is correct
31 Incorrect 3 ms 6100 KB Output isn't correct
32 Correct 3 ms 6100 KB Output is correct
33 Incorrect 6 ms 6356 KB Output isn't correct
34 Correct 6 ms 6356 KB Output is correct
35 Correct 20 ms 6436 KB Output is correct
36 Incorrect 8 ms 6484 KB Output isn't correct
37 Correct 8 ms 6416 KB Output is correct
38 Correct 27 ms 6512 KB Output is correct
39 Incorrect 8 ms 6588 KB Output isn't correct
40 Correct 11 ms 6484 KB Output is correct
41 Correct 32 ms 6476 KB Output is correct
42 Incorrect 9 ms 6628 KB Output isn't correct
43 Correct 10 ms 6612 KB Output is correct
44 Correct 38 ms 6612 KB Output is correct
45 Incorrect 11 ms 6656 KB Output isn't correct
46 Correct 11 ms 6740 KB Output is correct
47 Correct 43 ms 6740 KB Output is correct
48 Incorrect 12 ms 6740 KB Output isn't correct
49 Correct 12 ms 6868 KB Output is correct
50 Correct 48 ms 6868 KB Output is correct
51 Incorrect 14 ms 6868 KB Output isn't correct
52 Correct 14 ms 6968 KB Output is correct
53 Correct 64 ms 6952 KB Output is correct
54 Incorrect 15 ms 6988 KB Output isn't correct
55 Correct 16 ms 6952 KB Output is correct
56 Correct 73 ms 7072 KB Output is correct
57 Incorrect 18 ms 7120 KB Output isn't correct
58 Correct 17 ms 7124 KB Output is correct
59 Correct 92 ms 7228 KB Output is correct
60 Incorrect 19 ms 7292 KB Output isn't correct
61 Correct 19 ms 7212 KB Output is correct
62 Correct 99 ms 7224 KB Output is correct
63 Correct 83 ms 7276 KB Output is correct
64 Correct 149 ms 7276 KB Output is correct
65 Correct 118 ms 7276 KB Output is correct
66 Incorrect 103 ms 7280 KB Output isn't correct
67 Correct 89 ms 7280 KB Output is correct
68 Correct 39 ms 7244 KB Output is correct
69 Correct 39 ms 7212 KB Output is correct
70 Correct 35 ms 7200 KB Output is correct
71 Correct 40 ms 7244 KB Output is correct
72 Incorrect 25 ms 7252 KB Output isn't correct
73 Incorrect 32 ms 7460 KB Output isn't correct
74 Correct 45 ms 7500 KB Output is correct
75 Correct 67 ms 7456 KB Output is correct
76 Correct 47 ms 7500 KB Output is correct
77 Correct 49 ms 7548 KB Output is correct
78 Correct 60 ms 7536 KB Output is correct
79 Correct 44 ms 7528 KB Output is correct
80 Correct 49 ms 7504 KB Output is correct
81 Correct 52 ms 7528 KB Output is correct
82 Correct 47 ms 7508 KB Output is correct
83 Correct 60 ms 7428 KB Output is correct
84 Correct 56 ms 7492 KB Output is correct
85 Correct 58 ms 7508 KB Output is correct
86 Correct 63 ms 7492 KB Output is correct
87 Correct 59 ms 7388 KB Output is correct
88 Correct 70 ms 7440 KB Output is correct
89 Correct 61 ms 7332 KB Output is correct
90 Correct 66 ms 7436 KB Output is correct
91 Correct 64 ms 7440 KB Output is correct
92 Correct 80 ms 7340 KB Output is correct