Submission #446605

# Submission time Handle Problem Language Result Execution time Memory
446605 2021-07-22T16:52:19 Z JerryLiu06 Mecho (IOI09_mecho) C++17
9 / 100
203 ms 6356 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
 
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
 
const int MOD = 1e9 + 7;
const int MX = 810;
const ll INF = 1e18;

const int DIR[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };

int N, S; char G[MX][MX]; int SX, SY, EX, EY;

int distToHive[MX][MX], distToStart[MX][MX];

bool valid(int X, int Y) { return X >= 1 && X <= N && Y >= 1 && Y <= N; }

bool valid(int tim) {
    memset(distToStart, -1, sizeof distToStart);

    distToStart[SX][SY] = 0; 

    queue<pi> Q; Q.push({SX, SY});

    while (!Q.empty()) {
        pi cur = Q.front(); Q.pop();

        if (cur.f == EX && cur.s == EY) return true;

        F0R(i, 4) {
            int nx = cur.f + DIR[i][0];
            int ny = cur.s + DIR[i][1];

            if (!valid(nx, ny)) continue;

            if (G[nx][ny] != 'T' && distToStart[nx][ny] == -1) {
                distToStart[nx][ny] = distToStart[cur.f][cur.s] + 1;

                if (distToHive[nx][ny] != -1 && distToStart[nx][ny] / S + tim >= distToHive[nx][ny]) {
                    continue;
                }
                Q.push({nx, ny});
            }
        }
    }
    return false;
}

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

    cin >> N >> S; queue<pi> Q; memset(distToHive, -1, sizeof distToHive);
    
    FOR(i, 1, N + 1) FOR(j, 1, N + 1) {
        char C; cin >> C; if (C == 'M') { SX = i, SY = j; } if (C == 'D') { EX = i, EY = j; }

        if (C == 'H') { Q.push({i, j}); distToHive[i][j] = 0; }
    }
    while (!Q.empty()) {
        pi cur = Q.front(); Q.pop();

        F0R(i, 4) {
            int nx = cur.f + DIR[i][0];
            int ny = cur.s + DIR[i][1];

            if (!valid(nx, ny)) continue; 

            if (distToHive[nx][ny] == -1 && G[nx][ny] != 'T' && G[nx][ny] != 'D') {
                distToHive[nx][ny] = distToHive[cur.f][cur.s] + 1;
                
                Q.push({nx, ny});
            }
        }
    }
    int low = 0; int high = N; int res = -1;

    while (low <= high) {
        int mid = (low + high) / 2;

        if (valid(mid)) {
            low = mid + 1; res = mid;
        }
        else {
            high = mid - 1;
        }
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5452 KB Output is correct
2 Incorrect 3 ms 5452 KB Output isn't correct
3 Correct 3 ms 5452 KB Output is correct
4 Incorrect 3 ms 5440 KB Output isn't correct
5 Correct 3 ms 5452 KB Output is correct
6 Incorrect 3 ms 5452 KB Output isn't correct
7 Incorrect 94 ms 6080 KB Output isn't correct
8 Correct 3 ms 5452 KB Output is correct
9 Incorrect 3 ms 5452 KB Output isn't correct
10 Correct 4 ms 5324 KB Output is correct
11 Correct 3 ms 5452 KB Output is correct
12 Incorrect 3 ms 5432 KB Output isn't correct
13 Incorrect 3 ms 5452 KB Output isn't correct
14 Correct 4 ms 5360 KB Output is correct
15 Incorrect 3 ms 5452 KB Output isn't correct
16 Incorrect 4 ms 5420 KB Output isn't correct
17 Incorrect 3 ms 5456 KB Output isn't correct
18 Incorrect 3 ms 5452 KB Output isn't correct
19 Incorrect 3 ms 5452 KB Output isn't correct
20 Incorrect 3 ms 5452 KB Output isn't correct
21 Incorrect 3 ms 5452 KB Output isn't correct
22 Incorrect 3 ms 5452 KB Output isn't correct
23 Incorrect 3 ms 5452 KB Output isn't correct
24 Incorrect 3 ms 5368 KB Output isn't correct
25 Incorrect 3 ms 5452 KB Output isn't correct
26 Incorrect 4 ms 5452 KB Output isn't correct
27 Incorrect 3 ms 5452 KB Output isn't correct
28 Incorrect 4 ms 5452 KB Output isn't correct
29 Incorrect 3 ms 5452 KB Output isn't correct
30 Incorrect 4 ms 5452 KB Output isn't correct
31 Incorrect 3 ms 5452 KB Output isn't correct
32 Incorrect 4 ms 5452 KB Output isn't correct
33 Incorrect 9 ms 5580 KB Output isn't correct
34 Incorrect 17 ms 5580 KB Output isn't correct
35 Incorrect 35 ms 5452 KB Output isn't correct
36 Incorrect 12 ms 5616 KB Output isn't correct
37 Incorrect 21 ms 5616 KB Output isn't correct
38 Incorrect 44 ms 5580 KB Output isn't correct
39 Incorrect 11 ms 5656 KB Output isn't correct
40 Incorrect 26 ms 5580 KB Output isn't correct
41 Incorrect 53 ms 5660 KB Output isn't correct
42 Incorrect 14 ms 5708 KB Output isn't correct
43 Incorrect 32 ms 5708 KB Output isn't correct
44 Incorrect 70 ms 5704 KB Output isn't correct
45 Incorrect 19 ms 5616 KB Output isn't correct
46 Incorrect 39 ms 5732 KB Output isn't correct
47 Incorrect 81 ms 5708 KB Output isn't correct
48 Incorrect 18 ms 5804 KB Output isn't correct
49 Incorrect 50 ms 5816 KB Output isn't correct
50 Incorrect 105 ms 5708 KB Output isn't correct
51 Incorrect 20 ms 5836 KB Output isn't correct
52 Incorrect 54 ms 5868 KB Output isn't correct
53 Incorrect 134 ms 5880 KB Output isn't correct
54 Incorrect 24 ms 5948 KB Output isn't correct
55 Incorrect 63 ms 5940 KB Output isn't correct
56 Incorrect 136 ms 5928 KB Output isn't correct
57 Incorrect 26 ms 6016 KB Output isn't correct
58 Incorrect 76 ms 6008 KB Output isn't correct
59 Incorrect 178 ms 6008 KB Output isn't correct
60 Incorrect 30 ms 6068 KB Output isn't correct
61 Incorrect 77 ms 6072 KB Output isn't correct
62 Incorrect 203 ms 6080 KB Output isn't correct
63 Incorrect 29 ms 5952 KB Output isn't correct
64 Incorrect 32 ms 6072 KB Output isn't correct
65 Incorrect 29 ms 5952 KB Output isn't correct
66 Incorrect 29 ms 6088 KB Output isn't correct
67 Incorrect 30 ms 6088 KB Output isn't correct
68 Incorrect 32 ms 6236 KB Output isn't correct
69 Incorrect 33 ms 6212 KB Output isn't correct
70 Incorrect 35 ms 6220 KB Output isn't correct
71 Incorrect 39 ms 6204 KB Output isn't correct
72 Incorrect 34 ms 6172 KB Output isn't correct
73 Incorrect 37 ms 6344 KB Output isn't correct
74 Correct 62 ms 6340 KB Output is correct
75 Incorrect 73 ms 6356 KB Output isn't correct
76 Correct 70 ms 6348 KB Output is correct
77 Incorrect 73 ms 6340 KB Output isn't correct
78 Correct 101 ms 6212 KB Output is correct
79 Incorrect 59 ms 6312 KB Output isn't correct
80 Incorrect 74 ms 6212 KB Output isn't correct
81 Incorrect 87 ms 6204 KB Output isn't correct
82 Incorrect 69 ms 6320 KB Output isn't correct
83 Incorrect 99 ms 6324 KB Output isn't correct
84 Correct 88 ms 6216 KB Output is correct
85 Incorrect 87 ms 6276 KB Output isn't correct
86 Incorrect 80 ms 6292 KB Output isn't correct
87 Incorrect 86 ms 6220 KB Output isn't correct
88 Incorrect 99 ms 6228 KB Output isn't correct
89 Correct 93 ms 6236 KB Output is correct
90 Incorrect 85 ms 6192 KB Output isn't correct
91 Incorrect 87 ms 6328 KB Output isn't correct
92 Incorrect 92 ms 6112 KB Output isn't correct