Submission #393885

# Submission time Handle Problem Language Result Execution time Memory
393885 2021-04-24T18:52:42 Z MaisyDoge13 Mecho (IOI09_mecho) C++17
38 / 100
255 ms 16316 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <array>
#include <set>
#include <climits>
#include <map>
#include <memory>
#include <string>
#include <deque>
using namespace std;

#define input "mecho.in"
#define output "mecho.out"
#define int long long
int n, s;
int ans=-1; //will be maxed during the binary search
vector<vector<int>> bees_reach;
deque<pair<int, int>> bees_bfs; //r, c start off while taking input
vector<string> a;//input field
vector<vector<int>> reach_copy;
deque<pair<int, int>> bfs_copy;
vector<pair<int, int>> dirs = {
    {1, 0},
    {-1, 0},
    {0, 1},
    {0, -1}
};
bool check(int m) {
    vector<vector<int>> mecho_reach = reach_copy;
    deque<pair<int, int>> mecho_bfs = bfs_copy;

    //do bfs with mecho's location except mech can never go to a tile with bees there less than or equal to (m*s)+steps
    while (!mecho_bfs.empty()) {
        pair<int, int> curr=mecho_bfs.front();
        mecho_bfs.pop_front();
        int r=curr.first, c=curr.second;
        int curr_steps=mecho_reach[r][c];
        //cout << "r " << r << " c " << c << " curr_steps " <<  curr_steps << endl;
        if (a[r][c]=='D') {
            return 1;
        }
        for (pair<int, int> dir: dirs) {
            int new_r=r+dir.first, new_c=c+dir.second;
            if (new_r<0 || new_r>=n || new_c<0 || new_c>=n || a[new_r][new_c]=='T' || mecho_reach[new_r][new_c]!=-1) continue;
            if (bees_reach[new_r][new_c]<(m*s)+curr_steps+1 && bees_reach[new_r][new_c]!=-1) continue;
            mecho_reach[new_r][new_c]=curr_steps+1;
            mecho_bfs.push_back({new_r, new_c});
        }
    }


    return 0;
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen(input, "r", stdin);
    //freopen(output, "w", stdout);
    cin >> n >> s;
    bees_reach.resize(n, vector<int>(n, -1));
    reach_copy.resize(n, vector<int>(n, -1));
    a.reserve(n);
    for (int r=0;r<n;r++) {
        string s; cin >> s;
        a.push_back(s);
        for (int c=0;c<n;c++) {
            if (a[r][c]=='H') {
                bees_bfs.push_back({r, c});
                bees_reach[r][c]=0;
            }
            else if (a[r][c]=='M') {
                bfs_copy.push_back({r, c});
                reach_copy[r][c]=0;
            }
        }   
    }
    while (!bees_bfs.empty()) {
        pair<int, int> curr=bees_bfs.front();
        bees_bfs.pop_front();
        int r=curr.first, c=curr.second; int curr_steps=bees_reach[r][c];
        for (pair<int, int> dir: dirs) {
            int new_r=r+dir.first, new_c=c+dir.second;
            if (new_r<0 || new_r>=n || new_c<0 || new_c>=n || a[new_r][new_c]=='T' || a[new_r][new_c]=='D') continue;
            if (bees_reach[new_r][new_c]==-1) {
                bees_reach[new_r][new_c]=curr_steps+s;
                bees_bfs.push_back({new_r, new_c});
            }
        }
    }
    int l=0, r=1000*1000;
    while (l<=r) {
        int m=(l+r)/2;
        //cout << m << endl;
        if (check(m)) {
            ans=m;
            l=m+1;
        }
        else {
            r=m-1;
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 167 ms 16220 KB Output is correct
8 Incorrect 1 ms 204 KB Output isn't correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Correct 1 ms 332 KB Output is correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Correct 1 ms 332 KB Output is correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Correct 1 ms 336 KB Output is correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Correct 1 ms 332 KB Output is correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Correct 1 ms 332 KB Output is correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Correct 1 ms 332 KB Output is correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Correct 1 ms 336 KB Output is correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Correct 1 ms 332 KB Output is correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 460 KB Output isn't correct
32 Correct 1 ms 460 KB Output is correct
33 Incorrect 9 ms 3396 KB Output isn't correct
34 Correct 7 ms 3380 KB Output is correct
35 Correct 29 ms 3376 KB Output is correct
36 Incorrect 7 ms 4300 KB Output isn't correct
37 Correct 7 ms 4300 KB Output is correct
38 Correct 40 ms 4388 KB Output is correct
39 Incorrect 17 ms 5452 KB Output isn't correct
40 Correct 10 ms 5324 KB Output is correct
41 Correct 48 ms 5416 KB Output is correct
42 Incorrect 23 ms 6572 KB Output isn't correct
43 Correct 16 ms 6524 KB Output is correct
44 Correct 64 ms 6592 KB Output is correct
45 Incorrect 26 ms 7856 KB Output isn't correct
46 Correct 15 ms 7836 KB Output is correct
47 Correct 88 ms 7852 KB Output is correct
48 Incorrect 33 ms 9352 KB Output isn't correct
49 Correct 18 ms 9252 KB Output is correct
50 Correct 102 ms 9292 KB Output is correct
51 Incorrect 42 ms 10840 KB Output isn't correct
52 Correct 21 ms 10796 KB Output is correct
53 Correct 127 ms 10828 KB Output is correct
54 Incorrect 48 ms 12604 KB Output isn't correct
55 Correct 30 ms 12460 KB Output is correct
56 Correct 145 ms 12448 KB Output is correct
57 Incorrect 52 ms 14344 KB Output isn't correct
58 Correct 31 ms 14220 KB Output is correct
59 Correct 167 ms 14268 KB Output is correct
60 Incorrect 35 ms 16084 KB Output isn't correct
61 Correct 34 ms 16216 KB Output is correct
62 Correct 208 ms 16276 KB Output is correct
63 Correct 176 ms 16208 KB Output is correct
64 Correct 255 ms 16196 KB Output is correct
65 Correct 235 ms 16168 KB Output is correct
66 Incorrect 204 ms 16188 KB Output isn't correct
67 Correct 171 ms 16160 KB Output is correct
68 Correct 109 ms 16252 KB Output is correct
69 Correct 108 ms 16244 KB Output is correct
70 Correct 98 ms 16232 KB Output is correct
71 Correct 90 ms 16248 KB Output is correct
72 Incorrect 82 ms 16264 KB Output isn't correct
73 Incorrect 83 ms 16260 KB Output isn't correct
74 Correct 120 ms 16252 KB Output is correct
75 Correct 135 ms 16276 KB Output is correct
76 Correct 125 ms 16276 KB Output is correct
77 Correct 125 ms 16256 KB Output is correct
78 Correct 129 ms 16260 KB Output is correct
79 Correct 112 ms 16316 KB Output is correct
80 Correct 119 ms 16208 KB Output is correct
81 Correct 132 ms 16252 KB Output is correct
82 Correct 107 ms 16252 KB Output is correct
83 Correct 153 ms 16260 KB Output is correct
84 Correct 138 ms 16192 KB Output is correct
85 Correct 150 ms 16312 KB Output is correct
86 Correct 158 ms 16240 KB Output is correct
87 Correct 142 ms 16180 KB Output is correct
88 Correct 196 ms 16276 KB Output is correct
89 Correct 155 ms 16224 KB Output is correct
90 Correct 164 ms 16228 KB Output is correct
91 Correct 183 ms 16192 KB Output is correct
92 Correct 183 ms 16252 KB Output is correct