답안 #771005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771005 2023-07-02T10:26:50 Z ind1v Mecho (IOI09_mecho) C++11
38 / 100
168 ms 9464 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];
long long d[N][N];
int 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:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     int m = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 8532 KB Output isn't correct
2 Incorrect 4 ms 8532 KB Output isn't correct
3 Incorrect 4 ms 8532 KB Output isn't correct
4 Incorrect 4 ms 8548 KB Output isn't correct
5 Correct 3 ms 8532 KB Output is correct
6 Correct 4 ms 8532 KB Output is correct
7 Correct 68 ms 9204 KB Output is correct
8 Incorrect 4 ms 8532 KB Output isn't correct
9 Correct 4 ms 8532 KB Output is correct
10 Correct 4 ms 8532 KB Output is correct
11 Correct 4 ms 8532 KB Output is correct
12 Incorrect 4 ms 8532 KB Output isn't correct
13 Incorrect 5 ms 8532 KB Output isn't correct
14 Correct 4 ms 8532 KB Output is correct
15 Incorrect 5 ms 8532 KB Output isn't correct
16 Correct 4 ms 8532 KB Output is correct
17 Incorrect 4 ms 8532 KB Output isn't correct
18 Correct 4 ms 8532 KB Output is correct
19 Incorrect 4 ms 8532 KB Output isn't correct
20 Correct 4 ms 8532 KB Output is correct
21 Incorrect 4 ms 8532 KB Output isn't correct
22 Correct 4 ms 8532 KB Output is correct
23 Incorrect 4 ms 8532 KB Output isn't correct
24 Correct 4 ms 8532 KB Output is correct
25 Incorrect 4 ms 8532 KB Output isn't correct
26 Correct 4 ms 8532 KB Output is correct
27 Incorrect 4 ms 8520 KB Output isn't correct
28 Correct 4 ms 8532 KB Output is correct
29 Incorrect 4 ms 8620 KB Output isn't correct
30 Correct 4 ms 8532 KB Output is correct
31 Incorrect 4 ms 8532 KB Output isn't correct
32 Correct 4 ms 8532 KB Output is correct
33 Incorrect 7 ms 8840 KB Output isn't correct
34 Correct 7 ms 8844 KB Output is correct
35 Correct 20 ms 8788 KB Output is correct
36 Incorrect 8 ms 8760 KB Output isn't correct
37 Correct 8 ms 8788 KB Output is correct
38 Correct 30 ms 8880 KB Output is correct
39 Incorrect 9 ms 8916 KB Output isn't correct
40 Correct 9 ms 8824 KB Output is correct
41 Correct 41 ms 8916 KB Output is correct
42 Incorrect 11 ms 8964 KB Output isn't correct
43 Correct 12 ms 8916 KB Output is correct
44 Correct 41 ms 8852 KB Output is correct
45 Incorrect 12 ms 9052 KB Output isn't correct
46 Correct 12 ms 9004 KB Output is correct
47 Correct 44 ms 8964 KB Output is correct
48 Incorrect 13 ms 9044 KB Output isn't correct
49 Correct 14 ms 8992 KB Output is correct
50 Correct 61 ms 9004 KB Output is correct
51 Incorrect 14 ms 8956 KB Output isn't correct
52 Correct 15 ms 8972 KB Output is correct
53 Correct 65 ms 8996 KB Output is correct
54 Incorrect 16 ms 9044 KB Output isn't correct
55 Correct 17 ms 9008 KB Output is correct
56 Correct 75 ms 9104 KB Output is correct
57 Incorrect 18 ms 9044 KB Output isn't correct
58 Correct 21 ms 9064 KB Output is correct
59 Correct 93 ms 9148 KB Output is correct
60 Incorrect 20 ms 9172 KB Output isn't correct
61 Correct 20 ms 9200 KB Output is correct
62 Correct 98 ms 9184 KB Output is correct
63 Correct 83 ms 9180 KB Output is correct
64 Correct 151 ms 9180 KB Output is correct
65 Correct 168 ms 9080 KB Output is correct
66 Incorrect 103 ms 9180 KB Output isn't correct
67 Correct 91 ms 9088 KB Output is correct
68 Correct 40 ms 9116 KB Output is correct
69 Correct 38 ms 9112 KB Output is correct
70 Correct 32 ms 9212 KB Output is correct
71 Correct 42 ms 9120 KB Output is correct
72 Incorrect 31 ms 9172 KB Output isn't correct
73 Incorrect 35 ms 9364 KB Output isn't correct
74 Correct 58 ms 9428 KB Output is correct
75 Correct 56 ms 9464 KB Output is correct
76 Correct 49 ms 9456 KB Output is correct
77 Correct 52 ms 9440 KB Output is correct
78 Correct 66 ms 9440 KB Output is correct
79 Correct 41 ms 9428 KB Output is correct
80 Correct 51 ms 9432 KB Output is correct
81 Correct 55 ms 9428 KB Output is correct
82 Correct 51 ms 9436 KB Output is correct
83 Correct 62 ms 9296 KB Output is correct
84 Correct 55 ms 9396 KB Output is correct
85 Correct 60 ms 9400 KB Output is correct
86 Correct 73 ms 9404 KB Output is correct
87 Correct 62 ms 9276 KB Output is correct
88 Correct 65 ms 9308 KB Output is correct
89 Correct 64 ms 9344 KB Output is correct
90 Correct 66 ms 9300 KB Output is correct
91 Correct 66 ms 9252 KB Output is correct
92 Correct 87 ms 9340 KB Output is correct