답안 #1072473

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072473 2024-08-23T19:39:45 Z 7again Mecho (IOI09_mecho) C++17
82 / 100
379 ms 7044 KB
#include <bits/stdc++.h>

using namespace std ;

const int N = 801 ;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};


int n , s ;
pair <int , int> Honey , Home ;
char a[N][N] ;

bool inside(int x , int y) {
    return (x >= 0 && y >= 0 && x < n && y < n && a[x][y] == 'G') ;
}
bool val(int x , int y) {
    return  x / s < y ;
}
int ok(int time) {

    int mn2[n + 4][n + 4] ;
    fill_n(&mn2[0][0] , (n + 4) * (n + 4) , 1e9) ;
    queue<pair <int , int>>  q2 ;
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < n ; j++) {
            if(a[i][j] == 'H') {
                q2.push({i, j}) ;
                mn2[i][j] = 0 ;
            }
        }
    }
    while(q2.size()) {
        pair <int , int> t = q2.front() ;
        q2.pop() ;
        for(int i = 0 ; i < 4 ; i++) {
            int x = t.first + dx[i] ;
            int y = t.second + dy[i] ;
            if(inside(x , y) &&  mn2[t.first][t.second] + 1 < mn2[x][y]) {
                mn2[x][y] = mn2[t.first][t.second] + 1 ;
                q2.push({x, y}) ;
            }
        }
    }

    int mn[n + 4][n + 4] ;
    fill_n(&mn[0][0] , (n + 4) * (n + 4) , 1e9 ) ;
    queue <pair <int , int>> q ;
    mn[Honey.first][Honey.second] = 0 ;
    if(mn2[Honey.first][Honey.second] > time)
        q.push(Honey) ;
    while(!q.empty()) {
        pair <int , int> t = q.front() ;
        q.pop() ;
        for(int i = 0 ; i < 4 ; i++) {
            int x = t.first + dx[i] ;
            int y = t.second + dy[i] ;
            if(inside(x , y) && val(mn[t.first][t.second] + 1 , mn2[x][y] - time) && mn[t.first][t.second] + 1 < mn[x][y]) {
                mn[x][y] = mn[t.first][t.second] + 1 ;
                q.push({x , y}) ;
            }
        }
    }

    for(int i = 0 ; i < 4 ; i++){
        int x = Home.first + dx[i] ;
        int y = Home.second + dy[i] ;
        if(inside(x , y) && val(mn[x][y] , mn2[x][y]  - time))
            return true ;
    }

    return  false ;
}
int main() {
    cin >> n >> s ;

    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < n ; j++) {
            cin >> a[i][j] ;
            if(a[i][j] == 'M')
                Honey = {i , j} ;
            if(a[i][j] == 'D')
                Home = {i , j} ;
        }
    }

    int l = 0 , r = n * n + 4 ;
    while(l <= r) {
        int m = l + (r - l) / 2 ;
        if(ok(m))
            l = m + 1 ;
        else
            r = m - 1 ;
    }
    cout << l - 1 << endl ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 292 ms 6840 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 23 ms 1628 KB Output is correct
34 Correct 23 ms 1712 KB Output is correct
35 Correct 39 ms 1628 KB Output is correct
36 Correct 30 ms 2140 KB Output is correct
37 Correct 28 ms 2136 KB Output is correct
38 Correct 51 ms 2140 KB Output is correct
39 Correct 39 ms 2392 KB Output is correct
40 Correct 37 ms 2396 KB Output is correct
41 Correct 82 ms 2396 KB Output is correct
42 Correct 48 ms 3044 KB Output is correct
43 Correct 42 ms 2904 KB Output is correct
44 Correct 84 ms 3048 KB Output is correct
45 Correct 59 ms 3416 KB Output is correct
46 Correct 54 ms 3416 KB Output is correct
47 Correct 100 ms 3540 KB Output is correct
48 Correct 74 ms 4096 KB Output is correct
49 Correct 61 ms 4088 KB Output is correct
50 Correct 119 ms 4100 KB Output is correct
51 Correct 90 ms 4692 KB Output is correct
52 Correct 75 ms 4688 KB Output is correct
53 Correct 148 ms 4692 KB Output is correct
54 Correct 100 ms 5180 KB Output is correct
55 Correct 87 ms 5200 KB Output is correct
56 Correct 185 ms 5460 KB Output is correct
57 Correct 112 ms 6000 KB Output is correct
58 Correct 100 ms 5796 KB Output is correct
59 Correct 196 ms 5976 KB Output is correct
60 Correct 132 ms 6752 KB Output is correct
61 Correct 112 ms 6480 KB Output is correct
62 Correct 224 ms 6736 KB Output is correct
63 Correct 314 ms 6740 KB Output is correct
64 Correct 379 ms 6724 KB Output is correct
65 Correct 344 ms 6736 KB Output is correct
66 Correct 316 ms 6736 KB Output is correct
67 Correct 316 ms 6724 KB Output is correct
68 Correct 320 ms 6736 KB Output is correct
69 Correct 319 ms 6740 KB Output is correct
70 Correct 296 ms 6744 KB Output is correct
71 Correct 307 ms 6756 KB Output is correct
72 Incorrect 303 ms 6696 KB Output isn't correct
73 Incorrect 291 ms 6996 KB Output isn't correct
74 Correct 277 ms 7044 KB Output is correct
75 Correct 290 ms 6996 KB Output is correct
76 Correct 266 ms 6796 KB Output is correct
77 Correct 283 ms 6996 KB Output is correct
78 Correct 270 ms 6736 KB Output is correct
79 Correct 259 ms 6976 KB Output is correct
80 Correct 262 ms 6736 KB Output is correct
81 Correct 271 ms 6740 KB Output is correct
82 Correct 259 ms 6740 KB Output is correct
83 Correct 286 ms 6944 KB Output is correct
84 Correct 283 ms 6696 KB Output is correct
85 Correct 293 ms 6740 KB Output is correct
86 Correct 272 ms 6940 KB Output is correct
87 Correct 282 ms 6736 KB Output is correct
88 Correct 269 ms 6736 KB Output is correct
89 Correct 279 ms 6992 KB Output is correct
90 Correct 276 ms 6892 KB Output is correct
91 Correct 287 ms 6992 KB Output is correct
92 Correct 290 ms 6736 KB Output is correct