답안 #585387

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585387 2022-06-28T19:17:58 Z Andrei_Calota Mecho (IOI09_mecho) C++14
28 / 100
173 ms 6352 KB
#include <bits/stdc++.h>

using namespace std;
const int NMAX = 8e2;
const int VISUAL = 4;

int dl[] = { -1, 0, 1,  0 };
int dc[] = {  0, 1, 0, -1 };
int n, step; int bee_dist[2 + NMAX][2 + NMAX];
char forest[2 + NMAX][2 + NMAX]; int dist[2 + NMAX][2 + NMAX];
pair<int, int> honey, house;

vector<pair<int, int>> bees;
void bee_spread () {
   queue<pair<int, int>> q;
   for ( auto pos : bees ) {
      q.push ( pos );
      bee_dist[pos.first][pos.second] = 1;
   }
   while ( !q.empty () ) {
      pair<int, int> start = q.front (); q.pop ();
      int line = start.first, column = start.second;
      for ( int dir = 0; dir < VISUAL; dir ++ ) {
         int new_line = line + dl[dir];
         int new_col = column + dc[dir];
         if ( forest[new_line][new_col] != 'T' && bee_dist[new_line][new_col] == 0 ) {
           bee_dist[new_line][new_col] = bee_dist[line][column] + 1;
           q.push ( {new_line, new_col} );
         }
      }
   }
}
bool validation ( int time, pair<int, int> start ) {
   queue<pair<int, int>> q; q.push ( start );
   dist[start.first][start.second] = 1;
   while ( !q.empty () ) {
      start = q.front (); q.pop ();
      int line = start.first, column = start.second;
      for ( int dir = 0; dir < VISUAL; dir ++ ) {
         int new_line = line + dl[dir];
         int new_col = column + dc[dir];
         if ( (forest[new_line][new_col] == 'D' || forest[new_line][new_col] == 'G') && dist[new_line][new_col] == 0 ) {
           int need = dist[line][column] / step;
           if ( need + time < bee_dist[new_line][new_col] ) {
             q.push ( {new_line, new_col} );
             dist[new_line][new_col] = dist[line][column] + 1;
           }
         }
      }
   }
   if ( dist[house.first][house.second] )
     return true;
   return false;
}

void reset_dist () {
   for ( int i = 1; i <= n; i ++ )
      for ( int j = 1; j <= n; j ++ )
         dist[i][j] = 0;
}
void solve () {
   int left = 0, right = n; int answer = -1;
   while ( left <= right ) {
      int time = left + (right - left) / 2;
      int status = validation ( time, honey );
      if ( status == true ) {
        answer = time;
        left = time + 1;
      }
      else
        right = time - 1;
      reset_dist ();
   }
   cout << answer;
}
int main()
{
   cin >> n >> step; cin.get ();
   for ( int line = 1; line <= n; line ++ ) {
      for ( int column = 1; column <= n; column ++ ) {
         forest[line][column] = cin.get ();
         if ( forest[line][column] == 'M' )
           honey = {line, column};
         else if ( forest[line][column] == 'D' )
           house = {line, column};
         else if ( forest[line][column] == 'H' )
           bees.push_back ( {line, column} );
      }
      cin.get ();
   }
   for ( int indx = 0; indx < n + 2; indx ++ ) {
      forest[indx][0] = forest[indx][n + 1] = 'T';
      forest[0][indx] = forest[n + 1][indx] = 'T';
   }
   bee_spread ();
   for ( int i = 1; i <= n; i ++ )
      for ( int j = 1; j <= n; j ++ )
         bee_dist[i][j] --;
   solve ();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Correct 0 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 84 ms 6032 KB Output isn't correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 1 ms 724 KB Output isn't correct
13 Incorrect 1 ms 596 KB Output isn't correct
14 Correct 1 ms 724 KB Output is correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Incorrect 0 ms 468 KB Output isn't correct
17 Incorrect 0 ms 468 KB Output isn't correct
18 Incorrect 1 ms 468 KB Output isn't correct
19 Incorrect 1 ms 468 KB Output isn't correct
20 Incorrect 0 ms 468 KB Output isn't correct
21 Incorrect 1 ms 596 KB Output isn't correct
22 Incorrect 1 ms 596 KB Output isn't correct
23 Incorrect 1 ms 596 KB Output isn't correct
24 Incorrect 1 ms 596 KB Output isn't correct
25 Incorrect 1 ms 848 KB Output isn't correct
26 Incorrect 1 ms 724 KB Output isn't correct
27 Incorrect 1 ms 724 KB Output isn't correct
28 Incorrect 1 ms 724 KB Output isn't correct
29 Incorrect 1 ms 724 KB Output isn't correct
30 Incorrect 1 ms 724 KB Output isn't correct
31 Incorrect 1 ms 852 KB Output isn't correct
32 Incorrect 1 ms 852 KB Output isn't correct
33 Incorrect 15 ms 2772 KB Output isn't correct
34 Incorrect 16 ms 2748 KB Output isn't correct
35 Correct 18 ms 2796 KB Output is correct
36 Incorrect 19 ms 3148 KB Output isn't correct
37 Incorrect 21 ms 3028 KB Output isn't correct
38 Correct 26 ms 3152 KB Output is correct
39 Incorrect 23 ms 3376 KB Output isn't correct
40 Incorrect 28 ms 3500 KB Output isn't correct
41 Correct 35 ms 3480 KB Output is correct
42 Incorrect 28 ms 3720 KB Output isn't correct
43 Incorrect 33 ms 3792 KB Output isn't correct
44 Correct 40 ms 3760 KB Output is correct
45 Incorrect 36 ms 4184 KB Output isn't correct
46 Incorrect 41 ms 4180 KB Output isn't correct
47 Correct 48 ms 4184 KB Output is correct
48 Incorrect 43 ms 4528 KB Output isn't correct
49 Incorrect 55 ms 4532 KB Output isn't correct
50 Correct 56 ms 4540 KB Output is correct
51 Incorrect 50 ms 4896 KB Output isn't correct
52 Incorrect 57 ms 4836 KB Output isn't correct
53 Correct 66 ms 4900 KB Output is correct
54 Incorrect 59 ms 5204 KB Output isn't correct
55 Incorrect 73 ms 5216 KB Output isn't correct
56 Correct 80 ms 5252 KB Output is correct
57 Incorrect 65 ms 5592 KB Output isn't correct
58 Incorrect 79 ms 5708 KB Output isn't correct
59 Correct 101 ms 5596 KB Output is correct
60 Incorrect 78 ms 5944 KB Output isn't correct
61 Incorrect 89 ms 6024 KB Output isn't correct
62 Correct 108 ms 5888 KB Output is correct
63 Correct 104 ms 5880 KB Output is correct
64 Incorrect 173 ms 5956 KB Output isn't correct
65 Correct 135 ms 5952 KB Output is correct
66 Correct 112 ms 5952 KB Output is correct
67 Correct 107 ms 6012 KB Output is correct
68 Correct 58 ms 5980 KB Output is correct
69 Correct 53 ms 5964 KB Output is correct
70 Correct 52 ms 5984 KB Output is correct
71 Correct 50 ms 5864 KB Output is correct
72 Incorrect 45 ms 5980 KB Output isn't correct
73 Incorrect 42 ms 6148 KB Output isn't correct
74 Correct 60 ms 6248 KB Output is correct
75 Correct 65 ms 6248 KB Output is correct
76 Correct 66 ms 6256 KB Output is correct
77 Correct 63 ms 6252 KB Output is correct
78 Correct 75 ms 6352 KB Output is correct
79 Correct 63 ms 6212 KB Output is correct
80 Correct 72 ms 6144 KB Output is correct
81 Correct 78 ms 6188 KB Output is correct
82 Correct 68 ms 6220 KB Output is correct
83 Correct 77 ms 6140 KB Output is correct
84 Correct 75 ms 6172 KB Output is correct
85 Correct 78 ms 6180 KB Output is correct
86 Correct 95 ms 6104 KB Output is correct
87 Correct 79 ms 6072 KB Output is correct
88 Correct 77 ms 6092 KB Output is correct
89 Correct 77 ms 6012 KB Output is correct
90 Correct 81 ms 6092 KB Output is correct
91 Correct 83 ms 6120 KB Output is correct
92 Correct 80 ms 6036 KB Output is correct