답안 #1071527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1071527 2024-08-23T08:11:42 Z 7again Mecho (IOI09_mecho) C++17
0 / 100
494 ms 15288 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 is[N][N] ;
bool inside(int x , int y) {
    return (x >= 0 && y >= 0 && x < n && y < n && a[x][y] != 'T') ;
}

int ok(int time) {

    fill_n(&is[0][0] , N * N , false ) ;

    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}) ;
                is[i][j] = true ;
                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[t.first][t.second] + 1 < time) {
                is[x][y] = true ;
                mn2[x][y] = mn2[t.first][t.second] + 1 ;
                q2.push({x, y}) ;
            }
        }
    }
    // for(int i = 0 ; i < n ; i++) {
    //     for(int j = 0 ; j < n ; j++) {
    //         cout << is[i][j] << " " ;
    //     }
    //     cout << endl ;
    // }
    int mn[n][n] ;
    fill_n(&mn[0][0] , n * n , 1e9 ) ;
    queue <pair <int , int>> q ;
    mn[Honey.first][Honey.second] = 0 ;
    if(!is[Honey.first][Honey.second])
        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(is[x][y] == false && 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}) ;
            }
        }
    }
    // for(int i = 0 ; i < n ; i++) {
    //     for(int j = 0 ; j < n ; j++) {
    //         cout << mn[i][j] << " " ;
    //     }
    //     cout << endl ;
    // }
    if(mn[Home.first][Home.second] == 1e9)
        return  -1 ;
    int req = (mn[Home.first][Home.second] / time) + (mn[Home.first][Home.second] % time != 0) ;
    return time - req ;
}
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 = 1e9 ;
    while(l + 1 < r) {
        int m = l + (r - l) / 2 ;
        if(ok(m) >= 0)
            l = m ;
        else
            r = m ;
    }
    cout << ok(l) << endl ;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1372 KB Output isn't correct
2 Incorrect 1 ms 1372 KB Output isn't correct
3 Incorrect 1 ms 1372 KB Output isn't correct
4 Incorrect 1 ms 1372 KB Output isn't correct
5 Runtime error 2 ms 2396 KB Execution killed with signal 8
6 Runtime error 4 ms 2396 KB Execution killed with signal 8
7 Runtime error 402 ms 15124 KB Execution killed with signal 8
8 Runtime error 2 ms 2396 KB Execution killed with signal 8
9 Incorrect 1 ms 1372 KB Output isn't correct
10 Incorrect 1 ms 1372 KB Output isn't correct
11 Incorrect 1 ms 1372 KB Output isn't correct
12 Incorrect 2 ms 1372 KB Output isn't correct
13 Runtime error 4 ms 2532 KB Execution killed with signal 8
14 Runtime error 4 ms 2652 KB Execution killed with signal 8
15 Incorrect 1 ms 1372 KB Output isn't correct
16 Incorrect 1 ms 1372 KB Output isn't correct
17 Incorrect 1 ms 1372 KB Output isn't correct
18 Incorrect 1 ms 1372 KB Output isn't correct
19 Incorrect 1 ms 1372 KB Output isn't correct
20 Incorrect 1 ms 1372 KB Output isn't correct
21 Incorrect 2 ms 1372 KB Output isn't correct
22 Incorrect 2 ms 1372 KB Output isn't correct
23 Incorrect 2 ms 1372 KB Output isn't correct
24 Incorrect 2 ms 1372 KB Output isn't correct
25 Incorrect 2 ms 1372 KB Output isn't correct
26 Incorrect 2 ms 1372 KB Output isn't correct
27 Incorrect 3 ms 1372 KB Output isn't correct
28 Incorrect 3 ms 1372 KB Output isn't correct
29 Incorrect 3 ms 1488 KB Output isn't correct
30 Incorrect 3 ms 1556 KB Output isn't correct
31 Incorrect 3 ms 1372 KB Output isn't correct
32 Incorrect 3 ms 1372 KB Output isn't correct
33 Incorrect 40 ms 2836 KB Output isn't correct
34 Incorrect 36 ms 2648 KB Output isn't correct
35 Runtime error 52 ms 5204 KB Execution killed with signal 8
36 Incorrect 50 ms 3164 KB Output isn't correct
37 Incorrect 46 ms 3164 KB Output isn't correct
38 Runtime error 67 ms 5968 KB Execution killed with signal 8
39 Incorrect 62 ms 3644 KB Output isn't correct
40 Incorrect 60 ms 3636 KB Output isn't correct
41 Runtime error 91 ms 6716 KB Execution killed with signal 8
42 Incorrect 77 ms 3888 KB Output isn't correct
43 Incorrect 78 ms 3932 KB Output isn't correct
44 Runtime error 103 ms 7760 KB Execution killed with signal 8
45 Incorrect 94 ms 4444 KB Output isn't correct
46 Incorrect 94 ms 4620 KB Output isn't correct
47 Runtime error 130 ms 8528 KB Execution killed with signal 8
48 Incorrect 110 ms 4952 KB Output isn't correct
49 Incorrect 104 ms 4952 KB Output isn't correct
50 Runtime error 157 ms 9812 KB Execution killed with signal 8
51 Incorrect 130 ms 5724 KB Output isn't correct
52 Incorrect 119 ms 5720 KB Output isn't correct
53 Runtime error 173 ms 10836 KB Execution killed with signal 8
54 Incorrect 150 ms 6412 KB Output isn't correct
55 Incorrect 139 ms 6236 KB Output isn't correct
56 Runtime error 204 ms 12112 KB Execution killed with signal 8
57 Incorrect 188 ms 7000 KB Output isn't correct
58 Incorrect 171 ms 7004 KB Output isn't correct
59 Runtime error 230 ms 13432 KB Execution killed with signal 8
60 Incorrect 199 ms 7768 KB Output isn't correct
61 Incorrect 183 ms 7764 KB Output isn't correct
62 Runtime error 274 ms 14764 KB Execution killed with signal 8
63 Incorrect 374 ms 7844 KB Output isn't correct
64 Incorrect 371 ms 7764 KB Output isn't correct
65 Incorrect 379 ms 7760 KB Output isn't correct
66 Incorrect 391 ms 7652 KB Output isn't correct
67 Incorrect 383 ms 7772 KB Output isn't correct
68 Runtime error 399 ms 14932 KB Execution killed with signal 8
69 Runtime error 408 ms 14784 KB Execution killed with signal 8
70 Runtime error 395 ms 14932 KB Execution killed with signal 8
71 Runtime error 414 ms 14932 KB Execution killed with signal 8
72 Correct 472 ms 7868 KB Output is correct
73 Runtime error 404 ms 15288 KB Execution killed with signal 8
74 Incorrect 465 ms 8124 KB Output isn't correct
75 Incorrect 494 ms 8376 KB Output isn't correct
76 Incorrect 463 ms 7940 KB Output isn't correct
77 Incorrect 470 ms 8276 KB Output isn't correct
78 Incorrect 426 ms 8028 KB Output isn't correct
79 Incorrect 438 ms 8100 KB Output isn't correct
80 Incorrect 450 ms 8340 KB Output isn't correct
81 Incorrect 435 ms 7908 KB Output isn't correct
82 Incorrect 470 ms 8016 KB Output isn't correct
83 Incorrect 450 ms 7860 KB Output isn't correct
84 Incorrect 488 ms 8056 KB Output isn't correct
85 Incorrect 480 ms 8056 KB Output isn't correct
86 Incorrect 452 ms 8020 KB Output isn't correct
87 Incorrect 439 ms 7872 KB Output isn't correct
88 Runtime error 405 ms 15236 KB Execution killed with signal 8
89 Runtime error 417 ms 15204 KB Execution killed with signal 8
90 Runtime error 396 ms 15140 KB Execution killed with signal 8
91 Runtime error 401 ms 15188 KB Execution killed with signal 8
92 Runtime error 407 ms 15236 KB Execution killed with signal 8