Submission #759166

# Submission time Handle Problem Language Result Execution time Memory
759166 2023-06-15T20:08:39 Z bane Mecho (IOI09_mecho) C++17
84 / 100
159 ms 6308 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
 
int n, s, times[802][802];
vector<string> v(802);
pair<int, int> st, en;
 
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
 
inline bool valid(int x, int y) {
    return (x >= 0 && x < n && y >= 0 && y < n && v[x][y] != 'T');
}
 
bool check(int m) {
    if (m >= times[st.first][st.second]) return 0;
    queue<pair<int, int>> q;
    q.push(st);
    int vis[n + 2][n + 2];
    memset(vis, -1, sizeof(vis));
    vis[st.first][st.second] = 0;

      while (!q.empty()) {
          int x = q.front().first, y = q.front().second;
          q.pop();
          int dist = vis[x][y];
         // cout<<x<<" "<<y<<" "<<dist<<" "<<m<<endl;
          for (int d = 0; d < 4; d++) {
              int nx = x + dx[d], ny = y + dy[d];
              if (valid(nx, ny) && (dist + 1) / s + m< times[nx][ny] && vis[nx][ny] == -1) {
                   vis[nx][ny] = dist+1;
                   q.push({nx, ny});
                   if (make_pair(nx, ny) == en) return 1;
               }
           }
       }
    
    return 0;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    queue<pair<int, int>> h;
 
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        for (int j = 0; j < n; j++) {
            times[i][j] = (int)1e9;
            if (v[i][j] == 'M') st = {i, j};
            if (v[i][j] == 'H') {
                h.push({i, j});
                times[i][j] = 0;
            }
            if (v[i][j] == 'D') en = {i, j};
        }
    }
 
    while (h.size() > 0) {
        int x = h.front().first, y = h.front().second;
        h.pop();
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (valid(nx, ny) && times[x][y] + 1 < times[nx][ny]) {
                times[nx][ny] = times[x][y] + 1;
                h.push({nx, ny});
            }
        }
    }
 
    int l = 0, r = n * n + 100, ans = -1;
    while (l  <= r) {
        int m = (l + r) / 2;
        if (check(m)){
        	 l = m + 1;
        	ans = m;
        }else r = m - 1;
    }
 		cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 85 ms 6148 KB Output isn't correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 1 ms 468 KB Output isn't correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 2 ms 2004 KB Output is correct
34 Correct 4 ms 2004 KB Output is correct
35 Correct 17 ms 2060 KB Output is correct
36 Correct 4 ms 2288 KB Output is correct
37 Correct 4 ms 2388 KB Output is correct
38 Correct 22 ms 2388 KB Output is correct
39 Correct 5 ms 2772 KB Output is correct
40 Correct 5 ms 2772 KB Output is correct
41 Correct 31 ms 2772 KB Output is correct
42 Correct 6 ms 3156 KB Output is correct
43 Correct 5 ms 3156 KB Output is correct
44 Correct 37 ms 3084 KB Output is correct
45 Correct 5 ms 3540 KB Output is correct
46 Correct 5 ms 3540 KB Output is correct
47 Correct 55 ms 3540 KB Output is correct
48 Correct 6 ms 4036 KB Output is correct
49 Correct 6 ms 3924 KB Output is correct
50 Correct 52 ms 4028 KB Output is correct
51 Correct 7 ms 4436 KB Output is correct
52 Correct 10 ms 4436 KB Output is correct
53 Correct 65 ms 4436 KB Output is correct
54 Correct 8 ms 4948 KB Output is correct
55 Correct 11 ms 4996 KB Output is correct
56 Correct 102 ms 4984 KB Output is correct
57 Correct 11 ms 5476 KB Output is correct
58 Correct 9 ms 5460 KB Output is correct
59 Correct 96 ms 5500 KB Output is correct
60 Correct 10 ms 5968 KB Output is correct
61 Correct 10 ms 5964 KB Output is correct
62 Correct 140 ms 5972 KB Output is correct
63 Correct 101 ms 6160 KB Output is correct
64 Correct 159 ms 6028 KB Output is correct
65 Correct 129 ms 6044 KB Output is correct
66 Correct 114 ms 5972 KB Output is correct
67 Correct 102 ms 5972 KB Output is correct
68 Correct 39 ms 6056 KB Output is correct
69 Correct 38 ms 6052 KB Output is correct
70 Correct 27 ms 6084 KB Output is correct
71 Correct 30 ms 5980 KB Output is correct
72 Correct 23 ms 5996 KB Output is correct
73 Correct 26 ms 6252 KB Output is correct
74 Correct 54 ms 6308 KB Output is correct
75 Correct 69 ms 6228 KB Output is correct
76 Correct 73 ms 6228 KB Output is correct
77 Correct 58 ms 6304 KB Output is correct
78 Correct 77 ms 6284 KB Output is correct
79 Correct 48 ms 6288 KB Output is correct
80 Correct 61 ms 6284 KB Output is correct
81 Correct 64 ms 6248 KB Output is correct
82 Correct 50 ms 6224 KB Output is correct
83 Correct 75 ms 6228 KB Output is correct
84 Correct 74 ms 6176 KB Output is correct
85 Correct 79 ms 6228 KB Output is correct
86 Correct 76 ms 6196 KB Output is correct
87 Correct 89 ms 6184 KB Output is correct
88 Correct 73 ms 6132 KB Output is correct
89 Correct 90 ms 6192 KB Output is correct
90 Correct 90 ms 6168 KB Output is correct
91 Correct 84 ms 6196 KB Output is correct
92 Correct 102 ms 6188 KB Output is correct