답안 #254397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254397 2020-07-30T00:01:54 Z oscarsierra12 Mecho (IOI09_mecho) C++14
9 / 100
230 ms 12444 KB
#include<bits/stdc++.h>
using namespace std ;
 
const int N = 1000 ;

string ma[N] ;
int dist[N][N], dist2[N][N] ;
int X [] = {0,0,-1,1}, Y[] = {1,-1,0,0} ;
int visi[N][N] ;
int main() {
   int n, s ;
   cin >> n >> s ;
   for ( int i = 0 ; i < n ; ++i ) cin >> ma[i] ;
   queue <pair<int,int>> bfs ;
   pair<int,int> bg, en ;
   for ( int i = 0 ; i < n ; ++i ) {
      for ( int j = 0 ;  j < n ; ++j ) {
          if ( ma[i][j] == 'H' ) bfs.push({i,j}), dist2[i][j] = 0, visi[i][j] = 1 ;
          if ( ma[i][j] == 'T' ) visi[i][j] = 1 ;
          if ( ma[i][j] == 'M' ) bg = {i,j} ;
          if ( ma[i][j] == 'D' ) en = {i,j} ;
      }
   }
   while ( bfs.size() ) {
      pair<int,int> cur = bfs.front() ;
      bfs.pop() ;
      for ( int k = 0 ; k < 4 ; ++k ) {
         int nwx = X[k] + cur.first ;
         int nwy = Y[k] + cur.second ;
         if ( nwx < 0 || nwy < 0 || nwx >= n || nwy >= n || visi[nwx][nwy] ) continue ;
         visi[nwx][nwy] = 1 ;
         dist2[nwx][nwy] = 1 + dist2[cur.first][cur.second] ;
         bfs.push({nwx, nwy}) ; 
      }
   }
   int lw = 0, hg = 3*n ; 
   while ( lw <= hg ) {
      int mid = (lw+hg) / 2 ;
      memset ( visi, 0, sizeof visi ) ; 
      memset ( dist, 0, sizeof dist ) ; 
      bfs.push(bg) ;
      visi[bg.first][bg.second] = 1 ;
      while ( bfs.size() ) {
          pair<int,int> cur = bfs.front() ;
          bfs.pop() ;
          for ( int k = 0 ; k < 4 ; ++k ) {
             int nwx = X[k] + cur.first ;
             int nwy = Y[k] + cur.second ;
             if ( nwx < 0 || nwy < 0 || nwx >= n || nwy >= n || visi[nwx][nwy] || ma[nwx][nwy] == 'T' ) continue ;
             if ( (1 + dist[cur.first][cur.second]) / s + mid >= dist2[nwx][nwy] ) continue ;
             visi[nwx][nwy] = 1 ;
             dist[nwx][nwy] = 1 + dist[cur.first][cur.second] ;
             bfs.push({nwx, nwy}) ; 
          }
      }
      if ( visi[en.first][en.second] && dist[en.first][en.second] % 2 == s % 2 ) lw = mid+1 ;
      else hg = mid-1 ;
   }
   cout << hg << endl ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8192 KB Output is correct
2 Incorrect 6 ms 8192 KB Output isn't correct
3 Incorrect 8 ms 8192 KB Output isn't correct
4 Incorrect 9 ms 8192 KB Output isn't correct
5 Incorrect 6 ms 8192 KB Output isn't correct
6 Incorrect 9 ms 8192 KB Output isn't correct
7 Incorrect 165 ms 12152 KB Output isn't correct
8 Correct 6 ms 8192 KB Output is correct
9 Correct 8 ms 8192 KB Output is correct
10 Correct 7 ms 8192 KB Output is correct
11 Correct 7 ms 8192 KB Output is correct
12 Incorrect 8 ms 8448 KB Output isn't correct
13 Incorrect 8 ms 8320 KB Output isn't correct
14 Correct 10 ms 8448 KB Output is correct
15 Incorrect 7 ms 8192 KB Output isn't correct
16 Incorrect 7 ms 8192 KB Output isn't correct
17 Incorrect 10 ms 8320 KB Output isn't correct
18 Incorrect 9 ms 8320 KB Output isn't correct
19 Incorrect 8 ms 8320 KB Output isn't correct
20 Incorrect 7 ms 8320 KB Output isn't correct
21 Incorrect 7 ms 8320 KB Output isn't correct
22 Incorrect 8 ms 8320 KB Output isn't correct
23 Incorrect 11 ms 8320 KB Output isn't correct
24 Incorrect 8 ms 8320 KB Output isn't correct
25 Incorrect 10 ms 8472 KB Output isn't correct
26 Incorrect 12 ms 8448 KB Output isn't correct
27 Incorrect 8 ms 8448 KB Output isn't correct
28 Incorrect 13 ms 8448 KB Output isn't correct
29 Incorrect 8 ms 8448 KB Output isn't correct
30 Incorrect 8 ms 8448 KB Output isn't correct
31 Incorrect 8 ms 8448 KB Output isn't correct
32 Incorrect 9 ms 8448 KB Output isn't correct
33 Incorrect 25 ms 9728 KB Output isn't correct
34 Incorrect 35 ms 9728 KB Output isn't correct
35 Correct 40 ms 9848 KB Output is correct
36 Incorrect 30 ms 9984 KB Output isn't correct
37 Incorrect 38 ms 9988 KB Output isn't correct
38 Correct 52 ms 9984 KB Output is correct
39 Incorrect 35 ms 10112 KB Output isn't correct
40 Incorrect 43 ms 10112 KB Output isn't correct
41 Correct 66 ms 10232 KB Output is correct
42 Incorrect 43 ms 10660 KB Output isn't correct
43 Incorrect 56 ms 10744 KB Output isn't correct
44 Correct 74 ms 10668 KB Output is correct
45 Incorrect 52 ms 10872 KB Output isn't correct
46 Incorrect 70 ms 10880 KB Output isn't correct
47 Correct 92 ms 10872 KB Output is correct
48 Incorrect 57 ms 11128 KB Output isn't correct
49 Incorrect 81 ms 11128 KB Output isn't correct
50 Correct 105 ms 11128 KB Output is correct
51 Incorrect 63 ms 11384 KB Output isn't correct
52 Incorrect 81 ms 11384 KB Output isn't correct
53 Correct 117 ms 11384 KB Output is correct
54 Incorrect 75 ms 11640 KB Output isn't correct
55 Incorrect 101 ms 11512 KB Output isn't correct
56 Correct 176 ms 11640 KB Output is correct
57 Incorrect 86 ms 11768 KB Output isn't correct
58 Incorrect 114 ms 11768 KB Output isn't correct
59 Correct 188 ms 11896 KB Output is correct
60 Incorrect 106 ms 12024 KB Output isn't correct
61 Incorrect 133 ms 12024 KB Output isn't correct
62 Correct 193 ms 12024 KB Output is correct
63 Incorrect 152 ms 12128 KB Output isn't correct
64 Correct 212 ms 12024 KB Output is correct
65 Incorrect 230 ms 12024 KB Output isn't correct
66 Correct 167 ms 12024 KB Output is correct
67 Correct 149 ms 12024 KB Output is correct
68 Correct 96 ms 12152 KB Output is correct
69 Correct 77 ms 12024 KB Output is correct
70 Incorrect 75 ms 12152 KB Output isn't correct
71 Incorrect 76 ms 12024 KB Output isn't correct
72 Incorrect 62 ms 12028 KB Output isn't correct
73 Incorrect 81 ms 12400 KB Output isn't correct
74 Correct 105 ms 12280 KB Output is correct
75 Correct 118 ms 12408 KB Output is correct
76 Incorrect 114 ms 12408 KB Output isn't correct
77 Correct 105 ms 12444 KB Output is correct
78 Correct 108 ms 12280 KB Output is correct
79 Correct 81 ms 12280 KB Output is correct
80 Correct 97 ms 12408 KB Output is correct
81 Correct 100 ms 12408 KB Output is correct
82 Incorrect 111 ms 12280 KB Output isn't correct
83 Correct 109 ms 12280 KB Output is correct
84 Incorrect 171 ms 12408 KB Output isn't correct
85 Correct 109 ms 12280 KB Output is correct
86 Correct 110 ms 12336 KB Output is correct
87 Incorrect 116 ms 12280 KB Output isn't correct
88 Correct 132 ms 12280 KB Output is correct
89 Incorrect 184 ms 12280 KB Output isn't correct
90 Incorrect 143 ms 12280 KB Output isn't correct
91 Correct 142 ms 12280 KB Output is correct
92 Incorrect 130 ms 12280 KB Output isn't correct