Submission #597578

# Submission time Handle Problem Language Result Execution time Memory
597578 2022-07-16T10:46:12 Z BhavayGoyal Mecho (IOI09_mecho) C++14
37 / 100
186 ms 8136 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;

// -------------------------------------------------- Main Code --------------------------------------------------

const int N = 800;
int n, s;
int arr[N][N], beesDis[N][N], bearDis[N][N];
queue<pii> bees;
pii st, en;

int di[4] = {0, 0, 1, -1}, dj[4] = {1, -1, 0, 0};

bool isVal(int i, int j) {
    return (i >= 0 && j >= 0 && i < n && j < n && arr[i][j]);
}

void fillBees() {
    while (!bees.empty()) {
        auto f = bees.front(); bees.pop();
        for (int i = 0; i < 4; i++) {
            int ni = f.f+di[i], nj = f.s+dj[i];
            if (isVal(ni, nj) && beesDis[ni][nj] == -1) {
                beesDis[ni][nj] = beesDis[f.f][f.s]+1;
                bees.push({ni, nj});
            }
        }
    }
}

bool isPoss(int i, int j, int dis, int initTime) {
    return ((dis/s)+initTime < beesDis[i][j]);
}

bool isFiss(int initTime) {
    if (beesDis[st.f][st.s] <= initTime) return false;
    memset(bearDis, -1, sizeof bearDis);
    queue<pii> bear; bear.push({st.f, st.s});
    bearDis[st.f][st.s] = 0;
    while (!bear.empty()) {
        auto f = bear.front(); bear.pop();
        for (int i = 0; i < 4; i++) {
            int ni = f.f+di[i], nj = f.s+dj[i];
            if (isVal(ni, nj) && bearDis[ni][nj] == -1 && isPoss(ni, nj, bearDis[f.f][f.s]+1, initTime)) {
                bearDis[ni][nj] = bearDis[f.f][f.s]+1;
                bear.push({ni, nj});
            }
        }
    }

    for (int i = 0; i < 4; i++) {
        int ni = en.f+di[i], nj = en.s+dj[i];
        if (isVal(ni, nj) && bearDis[ni][nj] != -1) return true;
    }

    return false;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> s;
    memset(beesDis, -1, sizeof beesDis);
    memset(arr, 0, sizeof arr);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            char x; cin >> x;
            if (x == 'M') st = {i, j};
            if (x == 'D') en = {i, j};
            if (x == 'H') {
                bees.push({i, j});
                beesDis[i][j] = 0;
            }
            if (x == 'G' || x == 'M') arr[i][j] = 1;
        }
    }

    fillBees();

    int i = 0, j = n, ans = inf;
    while (i <= j) {
        int mid = (i+j)/2;
        if (isFiss(mid)) ans = mid, i = mid+1;
        else j = mid-1;
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7764 KB Output is correct
2 Correct 4 ms 7764 KB Output is correct
3 Correct 4 ms 7764 KB Output is correct
4 Correct 4 ms 7764 KB Output is correct
5 Correct 4 ms 7764 KB Output is correct
6 Correct 4 ms 7764 KB Output is correct
7 Correct 92 ms 8072 KB Output is correct
8 Incorrect 4 ms 7764 KB Output isn't correct
9 Correct 4 ms 7764 KB Output is correct
10 Correct 3 ms 7764 KB Output is correct
11 Correct 3 ms 7764 KB Output is correct
12 Incorrect 4 ms 7764 KB Output isn't correct
13 Correct 3 ms 7764 KB Output is correct
14 Incorrect 3 ms 7744 KB Output isn't correct
15 Incorrect 4 ms 7764 KB Output isn't correct
16 Incorrect 4 ms 7764 KB Output isn't correct
17 Incorrect 5 ms 7828 KB Output isn't correct
18 Incorrect 3 ms 7764 KB Output isn't correct
19 Incorrect 4 ms 7764 KB Output isn't correct
20 Incorrect 5 ms 7764 KB Output isn't correct
21 Incorrect 4 ms 7804 KB Output isn't correct
22 Incorrect 4 ms 7764 KB Output isn't correct
23 Incorrect 4 ms 7764 KB Output isn't correct
24 Incorrect 4 ms 7764 KB Output isn't correct
25 Incorrect 4 ms 7764 KB Output isn't correct
26 Incorrect 4 ms 7764 KB Output isn't correct
27 Incorrect 4 ms 7764 KB Output isn't correct
28 Incorrect 6 ms 7764 KB Output isn't correct
29 Incorrect 5 ms 7764 KB Output isn't correct
30 Incorrect 4 ms 7764 KB Output isn't correct
31 Incorrect 4 ms 7764 KB Output isn't correct
32 Incorrect 4 ms 7764 KB Output isn't correct
33 Incorrect 14 ms 7832 KB Output isn't correct
34 Incorrect 18 ms 7832 KB Output isn't correct
35 Correct 22 ms 7844 KB Output is correct
36 Incorrect 19 ms 7764 KB Output isn't correct
37 Incorrect 22 ms 7832 KB Output isn't correct
38 Correct 27 ms 7836 KB Output is correct
39 Incorrect 19 ms 7764 KB Output isn't correct
40 Incorrect 25 ms 7764 KB Output isn't correct
41 Correct 36 ms 7820 KB Output is correct
42 Incorrect 27 ms 7764 KB Output isn't correct
43 Incorrect 33 ms 7816 KB Output isn't correct
44 Correct 43 ms 7824 KB Output is correct
45 Incorrect 31 ms 7764 KB Output isn't correct
46 Incorrect 44 ms 7764 KB Output isn't correct
47 Correct 50 ms 7764 KB Output is correct
48 Incorrect 38 ms 7816 KB Output isn't correct
49 Incorrect 49 ms 7812 KB Output isn't correct
50 Correct 72 ms 7828 KB Output is correct
51 Incorrect 41 ms 7764 KB Output isn't correct
52 Incorrect 53 ms 7764 KB Output isn't correct
53 Correct 97 ms 7820 KB Output is correct
54 Incorrect 45 ms 7764 KB Output isn't correct
55 Incorrect 63 ms 7816 KB Output isn't correct
56 Correct 95 ms 7824 KB Output is correct
57 Incorrect 54 ms 7812 KB Output isn't correct
58 Incorrect 69 ms 7764 KB Output isn't correct
59 Correct 105 ms 7824 KB Output is correct
60 Incorrect 57 ms 7764 KB Output isn't correct
61 Incorrect 82 ms 7764 KB Output isn't correct
62 Correct 136 ms 7820 KB Output is correct
63 Correct 111 ms 7820 KB Output is correct
64 Incorrect 186 ms 7820 KB Output isn't correct
65 Correct 152 ms 7824 KB Output is correct
66 Correct 127 ms 7824 KB Output is correct
67 Incorrect 107 ms 7768 KB Output isn't correct
68 Correct 52 ms 7768 KB Output is correct
69 Correct 50 ms 7780 KB Output is correct
70 Correct 44 ms 7756 KB Output is correct
71 Correct 47 ms 7788 KB Output is correct
72 Correct 43 ms 7756 KB Output is correct
73 Correct 39 ms 8092 KB Output is correct
74 Correct 64 ms 8020 KB Output is correct
75 Correct 63 ms 8068 KB Output is correct
76 Correct 72 ms 8032 KB Output is correct
77 Correct 68 ms 8032 KB Output is correct
78 Incorrect 77 ms 8068 KB Output isn't correct
79 Correct 65 ms 8000 KB Output is correct
80 Correct 57 ms 8136 KB Output is correct
81 Correct 78 ms 8016 KB Output is correct
82 Correct 62 ms 8000 KB Output is correct
83 Correct 82 ms 8044 KB Output is correct
84 Correct 82 ms 8096 KB Output is correct
85 Correct 77 ms 7980 KB Output is correct
86 Correct 86 ms 8028 KB Output is correct
87 Correct 82 ms 8036 KB Output is correct
88 Correct 85 ms 7892 KB Output is correct
89 Correct 86 ms 7980 KB Output is correct
90 Correct 92 ms 7924 KB Output is correct
91 Correct 109 ms 7976 KB Output is correct
92 Correct 90 ms 7980 KB Output is correct