답안 #1071922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071922 2024-08-23T12:24:54 Z 7again Mecho (IOI09_mecho) C++17
45 / 100
384 ms 12372 KB
#include <bits/stdc++.h>

using namespace std ;

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


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] != 'T') ;
}
bool val(int x , int y) {
    return  x / s < y ;
}
int ok(int time) {

    int mn2[n][n] ;
    fill_n(&mn2[0][0] , n*n , 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][n] ;
    fill_n(&mn[0][0] , n * n , 1e9 ) ;
    queue <pair <int , int>> q ;
    mn[Honey.first][Honey.second] = 0 ;
    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(val(mn[t.first][t.second] + 1 , mn2[x][y] - time) && inside(x , y) && mn[t.first][t.second] + 1 < mn[x][y]) {
                mn[x][y] = mn[t.first][t.second] + 1 ;
                q.push({x , y}) ;
            }
        }
    }
    if(mn[Home.first][Home.second] == 1e9)
        return  0 ;
    return  1 ;
}
int main() {
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;

    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 + 1 ;
    while(l + 1 < r) {
        int m = (l + r) / 2 ;
        if(ok(m))
            l = m ;
        else
            r = m ;
    }
    cout << l << endl ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 272 ms 6968 KB Output isn't correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 468 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 Incorrect 1 ms 348 KB Output isn't 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 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 19 ms 1884 KB Output is correct
34 Correct 21 ms 1756 KB Output is correct
35 Correct 40 ms 1884 KB Output is correct
36 Correct 26 ms 2140 KB Output is correct
37 Correct 25 ms 2140 KB Output is correct
38 Runtime error 45 ms 3920 KB Execution killed with signal 11
39 Correct 32 ms 2652 KB Output is correct
40 Correct 40 ms 2652 KB Output is correct
41 Correct 72 ms 2652 KB Output is correct
42 Correct 41 ms 3132 KB Output is correct
43 Runtime error 11 ms 5720 KB Execution killed with signal 11
44 Correct 84 ms 3164 KB Output is correct
45 Correct 50 ms 3416 KB Output is correct
46 Runtime error 15 ms 6744 KB Execution killed with signal 11
47 Correct 100 ms 3420 KB Output is correct
48 Correct 57 ms 4184 KB Output is correct
49 Correct 57 ms 3672 KB Output is correct
50 Correct 131 ms 3676 KB Output is correct
51 Correct 73 ms 4184 KB Output is correct
52 Runtime error 18 ms 8528 KB Execution killed with signal 11
53 Correct 149 ms 4184 KB Output is correct
54 Correct 82 ms 4956 KB Output is correct
55 Correct 85 ms 4952 KB Output is correct
56 Correct 174 ms 4956 KB Output is correct
57 Correct 93 ms 5464 KB Output is correct
58 Correct 90 ms 5444 KB Output is correct
59 Correct 207 ms 5468 KB Output is correct
60 Correct 107 ms 6232 KB Output is correct
61 Runtime error 27 ms 12112 KB Execution killed with signal 11
62 Correct 227 ms 6232 KB Output is correct
63 Correct 300 ms 6236 KB Output is correct
64 Correct 384 ms 6236 KB Output is correct
65 Runtime error 113 ms 12112 KB Execution killed with signal 11
66 Correct 316 ms 6236 KB Output is correct
67 Incorrect 321 ms 6236 KB Output isn't correct
68 Correct 293 ms 6236 KB Output is correct
69 Runtime error 234 ms 12372 KB Execution killed with signal 11
70 Correct 310 ms 6232 KB Output is correct
71 Correct 308 ms 6236 KB Output is correct
72 Runtime error 169 ms 12156 KB Execution killed with signal 11
73 Incorrect 263 ms 6484 KB Output isn't correct
74 Correct 275 ms 6512 KB Output is correct
75 Correct 315 ms 6508 KB Output is correct
76 Correct 301 ms 6480 KB Output is correct
77 Correct 307 ms 6484 KB Output is correct
78 Incorrect 269 ms 6492 KB Output isn't correct
79 Correct 249 ms 6492 KB Output is correct
80 Correct 268 ms 6492 KB Output is correct
81 Correct 264 ms 6488 KB Output is correct
82 Correct 259 ms 6492 KB Output is correct
83 Correct 266 ms 6236 KB Output is correct
84 Correct 283 ms 6224 KB Output is correct
85 Correct 317 ms 6236 KB Output is correct
86 Correct 289 ms 6232 KB Output is correct
87 Correct 287 ms 6228 KB Output is correct
88 Correct 299 ms 6236 KB Output is correct
89 Correct 300 ms 6232 KB Output is correct
90 Correct 286 ms 6400 KB Output is correct
91 Correct 284 ms 6396 KB Output is correct
92 Correct 280 ms 6236 KB Output is correct