Submission #597581

# Submission time Handle Problem Language Result Execution time Memory
597581 2022-07-16T10:48:26 Z BhavayGoyal Mecho (IOI09_mecho) C++14
50 / 100
185 ms 8100 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;
    while (i <= j) {
        int mid = (i+j)/2;
        if (isFiss(mid)) i = mid+1;
        else j = mid-1;
    }
    cout << i-1 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7764 KB Output is correct
2 Correct 4 ms 7892 KB Output is correct
3 Correct 3 ms 7764 KB Output is correct
4 Correct 4 ms 7764 KB Output is correct
5 Correct 4 ms 7728 KB Output is correct
6 Correct 4 ms 7764 KB Output is correct
7 Correct 80 ms 7892 KB Output is correct
8 Correct 4 ms 7764 KB Output is correct
9 Correct 3 ms 7764 KB Output is correct
10 Correct 4 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 4 ms 7764 KB Output is correct
14 Correct 4 ms 7764 KB Output is correct
15 Incorrect 4 ms 7764 KB Output isn't correct
16 Incorrect 5 ms 7764 KB Output isn't correct
17 Incorrect 4 ms 7764 KB Output isn't correct
18 Incorrect 4 ms 7832 KB Output isn't correct
19 Incorrect 3 ms 7764 KB Output isn't correct
20 Incorrect 4 ms 7764 KB Output isn't correct
21 Incorrect 4 ms 7792 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 7836 KB Output isn't correct
27 Incorrect 4 ms 7764 KB Output isn't correct
28 Incorrect 4 ms 7764 KB Output isn't correct
29 Incorrect 6 ms 7764 KB Output isn't correct
30 Incorrect 4 ms 7764 KB Output isn't correct
31 Incorrect 5 ms 7764 KB Output isn't correct
32 Incorrect 5 ms 7792 KB Output isn't correct
33 Incorrect 13 ms 7764 KB Output isn't correct
34 Incorrect 18 ms 7768 KB Output isn't correct
35 Correct 20 ms 7764 KB Output is correct
36 Incorrect 15 ms 7764 KB Output isn't correct
37 Incorrect 24 ms 7840 KB Output isn't correct
38 Correct 33 ms 7764 KB Output is correct
39 Incorrect 19 ms 7832 KB Output isn't correct
40 Incorrect 31 ms 7816 KB Output isn't correct
41 Correct 39 ms 7816 KB Output is correct
42 Incorrect 24 ms 7840 KB Output isn't correct
43 Incorrect 32 ms 7764 KB Output isn't correct
44 Correct 42 ms 7828 KB Output is correct
45 Incorrect 30 ms 7832 KB Output isn't correct
46 Incorrect 39 ms 7836 KB Output isn't correct
47 Correct 52 ms 7824 KB Output is correct
48 Incorrect 34 ms 7764 KB Output isn't correct
49 Incorrect 52 ms 7816 KB Output isn't correct
50 Correct 70 ms 7820 KB Output is correct
51 Incorrect 39 ms 7764 KB Output isn't correct
52 Incorrect 53 ms 7764 KB Output isn't correct
53 Correct 81 ms 7896 KB Output is correct
54 Incorrect 46 ms 7764 KB Output isn't correct
55 Incorrect 63 ms 7808 KB Output isn't correct
56 Correct 85 ms 7820 KB Output is correct
57 Incorrect 50 ms 7764 KB Output isn't correct
58 Incorrect 78 ms 7816 KB Output isn't correct
59 Correct 107 ms 7820 KB Output is correct
60 Incorrect 57 ms 7768 KB Output isn't correct
61 Incorrect 78 ms 7812 KB Output isn't correct
62 Correct 127 ms 7824 KB Output is correct
63 Correct 107 ms 7760 KB Output is correct
64 Incorrect 185 ms 7892 KB Output isn't correct
65 Correct 143 ms 7764 KB Output is correct
66 Correct 124 ms 7756 KB Output is correct
67 Correct 111 ms 7764 KB Output is correct
68 Correct 51 ms 7784 KB Output is correct
69 Correct 45 ms 7756 KB Output is correct
70 Correct 43 ms 7744 KB Output is correct
71 Correct 47 ms 7792 KB Output is correct
72 Correct 35 ms 7784 KB Output is correct
73 Correct 39 ms 8020 KB Output is correct
74 Correct 59 ms 8100 KB Output is correct
75 Correct 58 ms 8036 KB Output is correct
76 Correct 62 ms 8020 KB Output is correct
77 Correct 64 ms 8100 KB Output is correct
78 Correct 67 ms 8072 KB Output is correct
79 Correct 56 ms 8068 KB Output is correct
80 Correct 52 ms 8004 KB Output is correct
81 Correct 65 ms 8020 KB Output is correct
82 Correct 60 ms 8068 KB Output is correct
83 Correct 83 ms 7992 KB Output is correct
84 Correct 67 ms 7972 KB Output is correct
85 Correct 76 ms 8028 KB Output is correct
86 Correct 71 ms 8036 KB Output is correct
87 Correct 81 ms 8032 KB Output is correct
88 Correct 86 ms 7976 KB Output is correct
89 Correct 78 ms 7984 KB Output is correct
90 Correct 81 ms 7980 KB Output is correct
91 Correct 98 ms 7976 KB Output is correct
92 Correct 89 ms 7912 KB Output is correct