Submission #972914

# Submission time Handle Problem Language Result Execution time Memory
972914 2024-05-01T10:13:41 Z jadai007 Mecho (IOI09_mecho) C++17
9 / 100
241 ms 65536 KB
#include<bits/stdc++.h>

using namespace std;

int n,s, bee[808][808], xx[] = {0, 0, -1, 1}, xy[] = {-1, 1, 0, 0}, bear[808][808], ans;
char mp[808][808];
pair<int, int> start, en;
queue<tuple<int, int, int>> q;
 
bool solve(int mid){
    for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bear[i][j] = 1e9;
    bear[start.first][start.second] = mid*s;
    q.emplace(start.first, start.second, mid*s);
    while(!q.empty()){
        int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
        if(x == en.first && y == en.second) return true;
        if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
        else if((w+s-1)/s > bee[x][y]) continue;
        bear[x][y] = w;
        for(int i = 0; i<4; ++i){
            int nx = x + xx[i];
            int ny = y + xy[i];
            if(nx < 1 || ny < 1 || nx > n || ny > n || mp[nx][ny] == 'T') continue;
            if(bear[nx][ny] > w + 1) q.emplace(nx, ny, w + 1);
        }
    }
    return false;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> s;
    for(int i = 1; i<=n; ++i){
        for(int j = 1; j<=n; ++j){
            cin >> mp[i][j];
            if(mp[i][j] == 'M') start = {i, j};
            else if(mp[i][j] == 'D') en = {i, j};
        }
    }
    for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bee[i][j] = 1e9;
    for(int i = 1; i<=n; ++i){
        for(int j = 1; j<=n; ++j){
            if(mp[i][j] == 'H'){
                bee[i][j] = 0;
                q.emplace(i, j, 0);
            }
        }
    }
    while(!q.empty()){
        int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front());
        q.pop();
        for(int i = 0; i<4; ++i){
            int nx = x + xx[i];
            int ny = y + xy[i];
            if(nx < 1 || n < 1 || nx > n || ny > n || mp[nx][ny] == 'T') continue;
            if(bee[nx][ny] > w + 1){
                bee[nx][ny] = w + 1;
                q.emplace(nx, ny, w + 1);
            }
        }
    }
    int l = 1, r = 1e9;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(solve(mid)){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    cout << ans;
}

Compilation message

mecho.cpp: In function 'bool solve(int)':
mecho.cpp:17:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   17 |         if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB Output isn't correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Runtime error 139 ms 65536 KB Execution killed with signal 9
8 Incorrect 1 ms 4440 KB Output isn't correct
9 Incorrect 8 ms 8024 KB Output isn't correct
10 Incorrect 1 ms 4444 KB Output isn't correct
11 Incorrect 1 ms 4444 KB Output isn't correct
12 Incorrect 1 ms 4440 KB Output isn't correct
13 Correct 1 ms 4444 KB Output is correct
14 Runtime error 129 ms 65536 KB Execution killed with signal 9
15 Incorrect 1 ms 4444 KB Output isn't correct
16 Incorrect 1 ms 4444 KB Output isn't correct
17 Incorrect 1 ms 4444 KB Output isn't correct
18 Incorrect 1 ms 4444 KB Output isn't correct
19 Incorrect 1 ms 4444 KB Output isn't correct
20 Incorrect 1 ms 4444 KB Output isn't correct
21 Incorrect 1 ms 4444 KB Output isn't correct
22 Incorrect 1 ms 4444 KB Output isn't correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Incorrect 1 ms 4440 KB Output isn't correct
25 Incorrect 1 ms 4444 KB Output isn't correct
26 Incorrect 1 ms 4444 KB Output isn't correct
27 Incorrect 1 ms 4444 KB Output isn't correct
28 Incorrect 1 ms 4444 KB Output isn't correct
29 Incorrect 1 ms 4444 KB Output isn't correct
30 Incorrect 1 ms 4444 KB Output isn't correct
31 Incorrect 1 ms 4444 KB Output isn't correct
32 Incorrect 1 ms 4444 KB Output isn't correct
33 Incorrect 4 ms 4700 KB Output isn't correct
34 Incorrect 5 ms 4700 KB Output isn't correct
35 Runtime error 142 ms 65536 KB Execution killed with signal 9
36 Incorrect 6 ms 4700 KB Output isn't correct
37 Incorrect 5 ms 4956 KB Output isn't correct
38 Runtime error 145 ms 65536 KB Execution killed with signal 9
39 Incorrect 6 ms 4956 KB Output isn't correct
40 Incorrect 6 ms 5084 KB Output isn't correct
41 Runtime error 153 ms 65536 KB Execution killed with signal 9
42 Incorrect 7 ms 5208 KB Output isn't correct
43 Incorrect 7 ms 5212 KB Output isn't correct
44 Runtime error 165 ms 65536 KB Execution killed with signal 9
45 Incorrect 9 ms 5212 KB Output isn't correct
46 Incorrect 9 ms 5212 KB Output isn't correct
47 Runtime error 165 ms 65536 KB Execution killed with signal 9
48 Incorrect 11 ms 5464 KB Output isn't correct
49 Incorrect 10 ms 5464 KB Output isn't correct
50 Runtime error 155 ms 65536 KB Execution killed with signal 9
51 Incorrect 12 ms 5724 KB Output isn't correct
52 Incorrect 13 ms 5724 KB Output isn't correct
53 Runtime error 158 ms 65536 KB Execution killed with signal 9
54 Incorrect 18 ms 5724 KB Output isn't correct
55 Incorrect 14 ms 5764 KB Output isn't correct
56 Runtime error 168 ms 65536 KB Execution killed with signal 9
57 Incorrect 16 ms 5980 KB Output isn't correct
58 Incorrect 16 ms 5976 KB Output isn't correct
59 Runtime error 203 ms 65536 KB Execution killed with signal 9
60 Incorrect 18 ms 5980 KB Output isn't correct
61 Incorrect 19 ms 5980 KB Output isn't correct
62 Runtime error 180 ms 65536 KB Execution killed with signal 9
63 Correct 83 ms 5980 KB Output is correct
64 Incorrect 241 ms 6172 KB Output isn't correct
65 Incorrect 141 ms 5980 KB Output isn't correct
66 Correct 100 ms 5980 KB Output is correct
67 Incorrect 93 ms 5976 KB Output isn't correct
68 Incorrect 205 ms 5980 KB Output isn't correct
69 Incorrect 186 ms 5980 KB Output isn't correct
70 Incorrect 230 ms 6236 KB Output isn't correct
71 Incorrect 219 ms 6232 KB Output isn't correct
72 Incorrect 40 ms 6236 KB Output isn't correct
73 Runtime error 157 ms 65536 KB Execution killed with signal 9
74 Runtime error 140 ms 65536 KB Execution killed with signal 9
75 Runtime error 157 ms 65536 KB Execution killed with signal 9
76 Runtime error 157 ms 65536 KB Execution killed with signal 9
77 Runtime error 141 ms 65536 KB Execution killed with signal 9
78 Runtime error 147 ms 65536 KB Execution killed with signal 9
79 Runtime error 150 ms 65536 KB Execution killed with signal 9
80 Runtime error 148 ms 65536 KB Execution killed with signal 9
81 Runtime error 185 ms 65536 KB Execution killed with signal 9
82 Runtime error 151 ms 65536 KB Execution killed with signal 9
83 Runtime error 169 ms 65536 KB Execution killed with signal 9
84 Runtime error 160 ms 65536 KB Execution killed with signal 9
85 Runtime error 155 ms 65536 KB Execution killed with signal 9
86 Runtime error 148 ms 65536 KB Execution killed with signal 9
87 Runtime error 151 ms 65536 KB Execution killed with signal 9
88 Runtime error 139 ms 65536 KB Execution killed with signal 9
89 Runtime error 145 ms 65536 KB Execution killed with signal 9
90 Runtime error 155 ms 65536 KB Execution killed with signal 9
91 Runtime error 137 ms 65536 KB Execution killed with signal 9
92 Runtime error 168 ms 65536 KB Execution killed with signal 9