답안 #1007485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007485 2024-06-25T04:04:23 Z huutuan Mecho (IOI09_mecho) C++14
84 / 100
140 ms 6492 KB
#include <bits/stdc++.h>

using namespace std;

const int N=810, dx[]={1, -1, 0, 0}, dy[]={0, 0, 1, -1};
int n, s;
char a[N][N];
int d[N][N], f[N][N];
int xm, ym, xd, yd;

bool check(int t){
   queue<pair<int, int>> q;
   memset(f, 0x3f, sizeof f);
   q.emplace(xm, ym); f[xm][ym]=t*s;
   if ((f[xm][ym]+s-1)/s>d[xm][ym]) return 0;
   while (q.size()){
      int x=q.front().first, y=q.front().second; q.pop();
      if (x==xd && y==yd) return 1;
      for (int i=0; i<4; ++i){
         int u=x+dx[i], v=y+dy[i];
         if (u<1 || v<1 || u>n || v>n || f[u][v]<1e9 || (f[x][y]+s)/s>d[x][y] || a[x][y]=='T') continue;
         f[u][v]=f[x][y]+1;
         q.emplace(u, v);
      }
   }
   return 0;
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> s;
   queue<pair<int, int>> q;
   memset(d, 0x3f, sizeof d);
   for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){
      cin >> a[i][j];
      if (a[i][j]=='M') xm=i, ym=j;
      if (a[i][j]=='D') xd=i, yd=j;
      if (a[i][j]=='H'){
         d[i][j]=0;
         q.emplace(i, j);
      }
   }
   while (q.size()){
      int x=q.front().first, y=q.front().second; q.pop();
      for (int i=0; i<4; ++i){
         int u=x+dx[i], v=y+dy[i];
         if (u<1 || v<1 || u>n || v>n || d[u][v]<1e9 || a[u][v]=='T' || a[u][v]=='D') continue;
         d[u][v]=d[x][y]+1;
         q.emplace(u, v);
      }
   }
   int l=1, r=1e6;
   while (l<=r){
      int mid=(l+r)>>1;
      if (check(mid)) l=mid+1;
      else r=mid-1;
   }
   cout << r << '\n';
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5468 KB Output is correct
2 Correct 2 ms 5464 KB Output is correct
3 Correct 2 ms 5468 KB Output is correct
4 Correct 2 ms 5468 KB Output is correct
5 Correct 2 ms 5468 KB Output is correct
6 Correct 2 ms 5464 KB Output is correct
7 Correct 44 ms 6348 KB Output is correct
8 Incorrect 2 ms 5480 KB Output isn't correct
9 Correct 2 ms 5556 KB Output is correct
10 Correct 2 ms 5468 KB Output is correct
11 Correct 2 ms 5468 KB Output is correct
12 Correct 2 ms 5468 KB Output is correct
13 Correct 2 ms 5468 KB Output is correct
14 Incorrect 2 ms 5468 KB Output isn't correct
15 Correct 2 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 2 ms 5468 KB Output is correct
18 Correct 2 ms 5468 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 2 ms 5468 KB Output is correct
21 Correct 2 ms 5468 KB Output is correct
22 Correct 2 ms 5468 KB Output is correct
23 Correct 2 ms 5468 KB Output is correct
24 Correct 2 ms 5468 KB Output is correct
25 Correct 2 ms 5464 KB Output is correct
26 Correct 2 ms 5468 KB Output is correct
27 Correct 2 ms 5468 KB Output is correct
28 Correct 2 ms 5468 KB Output is correct
29 Correct 2 ms 5468 KB Output is correct
30 Correct 2 ms 5468 KB Output is correct
31 Correct 3 ms 5468 KB Output is correct
32 Correct 2 ms 5468 KB Output is correct
33 Correct 4 ms 5724 KB Output is correct
34 Correct 4 ms 5724 KB Output is correct
35 Correct 16 ms 5880 KB Output is correct
36 Correct 4 ms 5724 KB Output is correct
37 Correct 5 ms 5720 KB Output is correct
38 Correct 20 ms 5920 KB Output is correct
39 Correct 5 ms 5720 KB Output is correct
40 Correct 5 ms 5724 KB Output is correct
41 Correct 27 ms 5956 KB Output is correct
42 Correct 6 ms 5980 KB Output is correct
43 Correct 6 ms 5992 KB Output is correct
44 Correct 32 ms 5980 KB Output is correct
45 Correct 6 ms 5980 KB Output is correct
46 Correct 7 ms 6032 KB Output is correct
47 Correct 39 ms 5980 KB Output is correct
48 Correct 7 ms 5980 KB Output is correct
49 Correct 7 ms 5980 KB Output is correct
50 Correct 47 ms 5980 KB Output is correct
51 Correct 8 ms 5976 KB Output is correct
52 Correct 9 ms 5980 KB Output is correct
53 Correct 54 ms 6096 KB Output is correct
54 Correct 9 ms 5984 KB Output is correct
55 Correct 10 ms 6152 KB Output is correct
56 Correct 62 ms 6136 KB Output is correct
57 Correct 10 ms 5980 KB Output is correct
58 Correct 11 ms 5980 KB Output is correct
59 Correct 78 ms 6180 KB Output is correct
60 Correct 11 ms 6232 KB Output is correct
61 Correct 12 ms 6048 KB Output is correct
62 Correct 83 ms 6216 KB Output is correct
63 Correct 95 ms 6212 KB Output is correct
64 Correct 140 ms 6236 KB Output is correct
65 Correct 134 ms 5980 KB Output is correct
66 Correct 121 ms 5972 KB Output is correct
67 Incorrect 98 ms 5968 KB Output isn't correct
68 Correct 44 ms 6228 KB Output is correct
69 Correct 34 ms 6228 KB Output is correct
70 Correct 27 ms 6232 KB Output is correct
71 Correct 24 ms 6236 KB Output is correct
72 Correct 22 ms 6236 KB Output is correct
73 Correct 20 ms 6492 KB Output is correct
74 Correct 35 ms 6488 KB Output is correct
75 Correct 41 ms 6492 KB Output is correct
76 Correct 34 ms 6492 KB Output is correct
77 Correct 36 ms 6492 KB Output is correct
78 Incorrect 38 ms 6232 KB Output isn't correct
79 Correct 32 ms 6492 KB Output is correct
80 Correct 36 ms 6492 KB Output is correct
81 Correct 40 ms 6236 KB Output is correct
82 Correct 42 ms 6304 KB Output is correct
83 Correct 41 ms 6232 KB Output is correct
84 Correct 38 ms 6236 KB Output is correct
85 Correct 41 ms 6236 KB Output is correct
86 Correct 46 ms 6260 KB Output is correct
87 Correct 43 ms 6224 KB Output is correct
88 Correct 42 ms 6236 KB Output is correct
89 Correct 46 ms 6208 KB Output is correct
90 Correct 48 ms 6236 KB Output is correct
91 Correct 47 ms 6232 KB Output is correct
92 Correct 41 ms 6236 KB Output is correct