Submission #1071906

# Submission time Handle Problem Language Result Execution time Memory
1071906 2024-08-23T12:17:23 Z 7again Mecho (IOI09_mecho) C++17
45 / 100
574 ms 12884 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 = 1e9 ;
    while(l + 1 < r) {
        int m = l + (r - l) / 2 ;
        if(ok(m))
            l = m ;
        else
            r = m ;
    }
    cout << l << endl ;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Incorrect 418 ms 6792 KB Output isn't correct
8 Incorrect 1 ms 344 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 1 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 2 ms 348 KB Output isn't correct
14 Incorrect 2 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 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 460 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 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 3 ms 344 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 32 ms 1884 KB Output is correct
34 Correct 31 ms 1880 KB Output is correct
35 Correct 60 ms 1856 KB Output is correct
36 Correct 51 ms 2140 KB Output is correct
37 Correct 47 ms 2136 KB Output is correct
38 Correct 79 ms 2140 KB Output is correct
39 Correct 57 ms 2648 KB Output is correct
40 Runtime error 33 ms 4816 KB Execution killed with signal 11
41 Correct 96 ms 2672 KB Output is correct
42 Correct 63 ms 2908 KB Output is correct
43 Correct 102 ms 2920 KB Output is correct
44 Correct 153 ms 3140 KB Output is correct
45 Correct 108 ms 3640 KB Output is correct
46 Correct 76 ms 3420 KB Output is correct
47 Runtime error 139 ms 6740 KB Execution killed with signal 11
48 Correct 107 ms 4188 KB Output is correct
49 Runtime error 56 ms 7768 KB Execution killed with signal 11
50 Correct 197 ms 4204 KB Output is correct
51 Correct 122 ms 4700 KB Output is correct
52 Correct 117 ms 4796 KB Output is correct
53 Correct 271 ms 4804 KB Output is correct
54 Correct 145 ms 5468 KB Output is correct
55 Runtime error 75 ms 10056 KB Execution killed with signal 11
56 Runtime error 301 ms 10196 KB Execution killed with signal 11
57 Correct 158 ms 6128 KB Output is correct
58 Correct 157 ms 5980 KB Output is correct
59 Correct 332 ms 5980 KB Output is correct
60 Correct 184 ms 6744 KB Output is correct
61 Runtime error 79 ms 12744 KB Execution killed with signal 11
62 Runtime error 342 ms 12804 KB Execution killed with signal 11
63 Correct 477 ms 6856 KB Output is correct
64 Correct 574 ms 6748 KB Output is correct
65 Runtime error 279 ms 12884 KB Execution killed with signal 11
66 Correct 542 ms 6740 KB Output is correct
67 Incorrect 458 ms 6860 KB Output isn't correct
68 Correct 464 ms 6736 KB Output is correct
69 Correct 544 ms 6692 KB Output is correct
70 Runtime error 456 ms 12880 KB Execution killed with signal 11
71 Runtime error 462 ms 12776 KB Execution killed with signal 11
72 Incorrect 506 ms 6740 KB Output isn't correct
73 Incorrect 457 ms 6956 KB Output isn't correct
74 Correct 494 ms 6996 KB Output is correct
75 Correct 493 ms 7144 KB Output is correct
76 Correct 461 ms 6972 KB Output is correct
77 Correct 507 ms 7144 KB Output is correct
78 Incorrect 423 ms 7000 KB Output isn't correct
79 Correct 464 ms 7112 KB Output is correct
80 Correct 410 ms 6924 KB Output is correct
81 Correct 435 ms 7108 KB Output is correct
82 Correct 441 ms 7248 KB Output is correct
83 Correct 391 ms 7076 KB Output is correct
84 Correct 415 ms 7004 KB Output is correct
85 Correct 402 ms 7072 KB Output is correct
86 Correct 412 ms 7072 KB Output is correct
87 Correct 446 ms 6880 KB Output is correct
88 Correct 400 ms 7004 KB Output is correct
89 Correct 413 ms 6996 KB Output is correct
90 Correct 412 ms 6996 KB Output is correct
91 Correct 470 ms 7024 KB Output is correct
92 Correct 415 ms 6840 KB Output is correct