Submission #583548

# Submission time Handle Problem Language Result Execution time Memory
583548 2022-06-25T14:34:50 Z Trent Mecho (IOI09_mecho) C++17
0 / 100
89 ms 14020 KB
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"

using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define open(g) string _name_ = g; freopen((_name_ + ".in").c_str(), "r", stdin); freopen((_name_ + ".out").c_str(), "w", stdout)
#define printArr(a, len) for(int asdf = 0; asdf < (len); ++asdf) cout << (a)[asdf] << ' '; cout << '\n';
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(i) i.begin(), i.end()
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

const int MN = 810, INF = 1e9 + 10;
struct coord{int r, c;};
struct bear{int r, c, sl;};
bool vis[MN][MN];
int bee[MN][MN], ber[MN][MN]; // minimum # of minutes needed to end here
char grid[MN][MN];
int dir[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int n, s;
int mr, mc;

bool ib(int r, int c){return 0 <= r && r < n && 0 <= c && c < n;}
bool iv(int r, int c){return ib(r, c) && grid[r][c] != 'T';}

// t = number of minutes bear eats
bool pos(int t){
    if(bee[mr][mc] == t) return false;
    deque<bear> bfs = {{mr, mc, 0}};
    forR(a, MN) forR(b, MN) vis[a][b] = false;
    forR(a, MN) forR(b, MN) ber[a][b] = 0;
    ber[mr][mc] = t;
    vis[mr][mc] = true;
    while(!bfs.empty()){
        auto [r, c, sl] = bfs.front();
        bfs.pop_front();
        assert(sl > 0 || ber[r][c] < bee[r][c]);
        if(grid[r][c] == 'D') {
            return true;
        }
        for(auto [rc, cc] : dir){
            auto [nr, nc] = pii{r+rc, c+cc};
            int dis = ber[r][c] + (sl == 0);
            int nsl = sl == 0 ? s - 1 : sl - 1;
            // cout << r << ' ' << c << ' ' << sl << ' ' << nr << ' ' << nc << ' ' << dis << ' ' << bee[nr][nc] << '\n';
            if(iv(nr, nc) && !vis[nr][nc] && (nsl != 0 || dis < bee[nr][nc])){
                ber[nr][nc] = dis;
                vis[nr][nc] = true;
                bfs.push_back({nr, nc, nsl});
            }
        }
    }
    return false;
}

signed main() {
    cin >> n >> s;
    deque<coord> bfs;
    forR(r, n) forR(c, n){
        cin >> grid[r][c];
        if(grid[r][c] == 'H') {
            bfs.push_back({r, c});
            vis[r][c] = true;
        } else if(grid[r][c] == 'M'){
            mr=r, mc=c;
        }
    }
    while(!bfs.empty()){
        auto [r, c] = bfs.front();
        bfs.pop_front();
        for(auto [cr, cc] : dir){
            auto [nr, nc] = pii {r + cr, c + cc};
            if(iv(nr, nc) && grid[nr][nc] != 'D' && !vis[nr][nc]){
                vis[nr][nc] = true;
                bee[nr][nc] = bee[r][c] + 1;
                bfs.push_back({nr, nc});
            }
        }
    }
    forR(r, MN) forR(c, MN) if(!vis[r][c]) bee[r][c] = INF;
    if(!pos(0)) cout << "-1\n";
    else {
        // TODO fix hi
        int lo=0, hi=MN * MN;
        while(hi - lo > 1){
            int mid = (lo + hi) / 2;
            if(pos(mid)) lo = mid;
            else hi = mid;
        }
        cout << lo << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 12116 KB Execution killed with signal 6
2 Runtime error 13 ms 12116 KB Execution killed with signal 6
3 Runtime error 9 ms 12116 KB Execution killed with signal 6
4 Runtime error 10 ms 12116 KB Execution killed with signal 6
5 Runtime error 9 ms 12116 KB Execution killed with signal 6
6 Runtime error 9 ms 12200 KB Execution killed with signal 6
7 Runtime error 78 ms 13624 KB Execution killed with signal 6
8 Correct 4 ms 5972 KB Output is correct
9 Runtime error 12 ms 12116 KB Execution killed with signal 6
10 Runtime error 9 ms 12116 KB Execution killed with signal 6
11 Runtime error 12 ms 12196 KB Execution killed with signal 6
12 Runtime error 10 ms 12244 KB Execution killed with signal 6
13 Runtime error 10 ms 12176 KB Execution killed with signal 6
14 Runtime error 11 ms 12268 KB Execution killed with signal 6
15 Runtime error 9 ms 12116 KB Execution killed with signal 6
16 Runtime error 10 ms 12116 KB Execution killed with signal 6
17 Runtime error 10 ms 12348 KB Execution killed with signal 6
18 Runtime error 9 ms 12116 KB Execution killed with signal 6
19 Runtime error 9 ms 12244 KB Execution killed with signal 6
20 Runtime error 10 ms 12116 KB Execution killed with signal 6
21 Runtime error 10 ms 12244 KB Execution killed with signal 6
22 Runtime error 10 ms 12244 KB Execution killed with signal 6
23 Runtime error 9 ms 12244 KB Execution killed with signal 6
24 Runtime error 11 ms 12244 KB Execution killed with signal 6
25 Runtime error 11 ms 12280 KB Execution killed with signal 6
26 Runtime error 10 ms 12224 KB Execution killed with signal 6
27 Runtime error 10 ms 12244 KB Execution killed with signal 6
28 Runtime error 10 ms 12244 KB Execution killed with signal 6
29 Runtime error 9 ms 12276 KB Execution killed with signal 6
30 Runtime error 9 ms 12272 KB Execution killed with signal 6
31 Runtime error 11 ms 12244 KB Execution killed with signal 6
32 Runtime error 9 ms 12244 KB Execution killed with signal 6
33 Runtime error 18 ms 12756 KB Execution killed with signal 6
34 Runtime error 19 ms 12756 KB Execution killed with signal 6
35 Runtime error 22 ms 12632 KB Execution killed with signal 6
36 Runtime error 21 ms 12748 KB Execution killed with signal 6
37 Runtime error 20 ms 12740 KB Execution killed with signal 6
38 Runtime error 23 ms 12832 KB Execution killed with signal 6
39 Runtime error 22 ms 12884 KB Execution killed with signal 6
40 Runtime error 24 ms 12892 KB Execution killed with signal 6
41 Runtime error 29 ms 12800 KB Execution killed with signal 6
42 Runtime error 25 ms 12908 KB Execution killed with signal 6
43 Runtime error 26 ms 12924 KB Execution killed with signal 6
44 Runtime error 30 ms 12872 KB Execution killed with signal 6
45 Runtime error 31 ms 12976 KB Execution killed with signal 6
46 Runtime error 33 ms 13012 KB Execution killed with signal 6
47 Runtime error 37 ms 13056 KB Execution killed with signal 6
48 Runtime error 33 ms 13124 KB Execution killed with signal 6
49 Runtime error 30 ms 13048 KB Execution killed with signal 6
50 Runtime error 39 ms 13076 KB Execution killed with signal 6
51 Runtime error 37 ms 13204 KB Execution killed with signal 6
52 Runtime error 40 ms 13104 KB Execution killed with signal 6
53 Runtime error 58 ms 13196 KB Execution killed with signal 6
54 Runtime error 42 ms 13256 KB Execution killed with signal 6
55 Runtime error 42 ms 13252 KB Execution killed with signal 6
56 Runtime error 50 ms 13236 KB Execution killed with signal 6
57 Runtime error 48 ms 13280 KB Execution killed with signal 6
58 Runtime error 45 ms 13364 KB Execution killed with signal 6
59 Runtime error 60 ms 13308 KB Execution killed with signal 6
60 Runtime error 55 ms 13360 KB Execution killed with signal 6
61 Runtime error 62 ms 13348 KB Execution killed with signal 6
62 Runtime error 60 ms 13472 KB Execution killed with signal 6
63 Runtime error 79 ms 13368 KB Execution killed with signal 6
64 Runtime error 87 ms 13412 KB Execution killed with signal 6
65 Runtime error 79 ms 13384 KB Execution killed with signal 6
66 Runtime error 86 ms 13360 KB Execution killed with signal 6
67 Correct 71 ms 6668 KB Output is correct
68 Runtime error 72 ms 13476 KB Execution killed with signal 6
69 Runtime error 81 ms 13472 KB Execution killed with signal 6
70 Runtime error 69 ms 13408 KB Execution killed with signal 6
71 Runtime error 68 ms 13440 KB Execution killed with signal 6
72 Runtime error 71 ms 13468 KB Execution killed with signal 6
73 Runtime error 70 ms 13900 KB Execution killed with signal 6
74 Runtime error 79 ms 14020 KB Execution killed with signal 6
75 Runtime error 70 ms 13992 KB Execution killed with signal 6
76 Runtime error 71 ms 13996 KB Execution killed with signal 6
77 Runtime error 80 ms 13916 KB Execution killed with signal 6
78 Runtime error 71 ms 13896 KB Execution killed with signal 6
79 Runtime error 72 ms 13868 KB Execution killed with signal 6
80 Runtime error 68 ms 13916 KB Execution killed with signal 6
81 Runtime error 68 ms 13948 KB Execution killed with signal 6
82 Runtime error 76 ms 13852 KB Execution killed with signal 6
83 Runtime error 67 ms 13848 KB Execution killed with signal 6
84 Runtime error 71 ms 13772 KB Execution killed with signal 6
85 Runtime error 81 ms 13772 KB Execution killed with signal 6
86 Runtime error 89 ms 13764 KB Execution killed with signal 6
87 Runtime error 73 ms 13884 KB Execution killed with signal 6
88 Runtime error 64 ms 13696 KB Execution killed with signal 6
89 Runtime error 88 ms 13716 KB Execution killed with signal 6
90 Runtime error 77 ms 13732 KB Execution killed with signal 6
91 Runtime error 80 ms 13880 KB Execution killed with signal 6
92 Runtime error 82 ms 13692 KB Execution killed with signal 6