Submission #1099928

# Submission time Handle Problem Language Result Execution time Memory
1099928 2024-10-12T06:00:44 Z chaoslong Mecho (IOI09_mecho) C++14
15 / 100
177 ms 10332 KB
// Calm down.
// Think three times, code twice.
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;

pii bd, en;
int n, s, dx[] {1, -1, 0, 0}, dy[] {0, 0, 1, -1}, d[1005][1005], d1[1005][1005];
char a[1005][1005];
queue<piii> q;

bool check(int x, int y) {
    if(x > n || x < 1 || y > n || y < 1 || a[x][y] == 'T') return false;
    return true;
}

bool kt(int mid) {
    memset(d1, 0, sizeof d1);
    q.push({mid * s, {bd.st, bd.nd}});
    while(q.size()) {
        int dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop();
        if(d1[x][y]) continue;
        d1[x][y] = 1;
        forr(i, 0, 3) {
            int nx = x + dx[i], ny = y + dy[i];
            if(!check(nx, ny)) continue;
            if((dxy + 1) % s == 0 && (dxy + 1) / s < d[nx][ny]) {
                q.push({dxy + 1, {nx, ny}});
            } else if((dxy + 1) % s != 0) {
                q.push({dxy + 1, {nx, ny}});
            }
        }
    }
    return d1[en.st][en.nd];
}

void to_nho_cau() {
    cin >> n >> s;
    memset(d, 63, sizeof d);
    forr(i, 1, n) {
        forr(j, 1, n) {
            cin >> a[i][j];
            if(a[i][j] == 'H') {
                d[i][j] = 0;
                q.push({0, {i, j}});
            }
            if(a[i][j] == 'M') bd = {i, j};
            if(a[i][j] == 'D') en = {i, j};
        }
    }
    while(q.size()) {
        int dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop();
        if(d[x][y] < dxy) continue;
        forr(i, 0, 3) {
            int nx = x + dx[i], ny = y + dy[i];
            if(!check(nx, ny) || a[nx][ny] == 'D') continue;
            if(dxy + 1 < d[nx][ny]) {
                d[nx][ny] = dxy + 1;
                q.push({dxy + 1, {nx, ny}});
            }
        }
    }
    int l = 0, r = 16000, ans = -1;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(kt(mid)) {
            ans = mid;
            l = mid + 1;
        } else r = mid - 1;
    }
    cout << ans << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
//    #ifdef LOCAL
//        freopen(file".inp","r",stdin);
//        freopen(file".out","w",stdout);
//    #endif
    int t = 1;
    //cin >> t;
    while(t--) to_nho_cau();
}
/*
1.self check:
2.long long
3.size of array
4.code for testing
5.initializing
6.modulo number
*/
/**
  ∧__∧
(`•ω• )づ__∧
(つ  /( •ω•。)
  しーJ (nnノ) pat pat
**/
/**  /\_/\
*   (= ._.)
*   / >☕ \>💻
**/

Compilation message

mecho.cpp:119:9: warning: "/*" within comment [-Wcomment]
  119 | /**  /\_/\
      |
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8420 KB Output is correct
2 Correct 4 ms 8284 KB Output is correct
3 Correct 4 ms 8148 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Incorrect 4 ms 8284 KB Output isn't correct
6 Incorrect 4 ms 8380 KB Output isn't correct
7 Incorrect 129 ms 9928 KB Output isn't correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 5 ms 8284 KB Output is correct
10 Correct 4 ms 8284 KB Output is correct
11 Incorrect 5 ms 8224 KB Output isn't correct
12 Incorrect 4 ms 8284 KB Output isn't correct
13 Incorrect 5 ms 8432 KB Output isn't correct
14 Incorrect 5 ms 8284 KB Output isn't correct
15 Correct 5 ms 8244 KB Output is correct
16 Incorrect 5 ms 8284 KB Output isn't correct
17 Correct 5 ms 8284 KB Output is correct
18 Incorrect 5 ms 8284 KB Output isn't correct
19 Correct 5 ms 8540 KB Output is correct
20 Incorrect 7 ms 8284 KB Output isn't correct
21 Correct 4 ms 8284 KB Output is correct
22 Incorrect 4 ms 8284 KB Output isn't correct
23 Correct 4 ms 8284 KB Output is correct
24 Incorrect 5 ms 8284 KB Output isn't correct
25 Correct 5 ms 8264 KB Output is correct
26 Incorrect 4 ms 8284 KB Output isn't correct
27 Correct 5 ms 8284 KB Output is correct
28 Incorrect 5 ms 8284 KB Output isn't correct
29 Correct 4 ms 8284 KB Output is correct
30 Incorrect 5 ms 8284 KB Output isn't correct
31 Correct 5 ms 8284 KB Output is correct
32 Incorrect 5 ms 8312 KB Output isn't correct
33 Incorrect 16 ms 8796 KB Output isn't correct
34 Incorrect 17 ms 8704 KB Output isn't correct
35 Incorrect 30 ms 8796 KB Output isn't correct
36 Incorrect 22 ms 8796 KB Output isn't correct
37 Incorrect 24 ms 8796 KB Output isn't correct
38 Incorrect 37 ms 8796 KB Output isn't correct
39 Incorrect 24 ms 8988 KB Output isn't correct
40 Incorrect 31 ms 8796 KB Output isn't correct
41 Incorrect 58 ms 8800 KB Output isn't correct
42 Incorrect 28 ms 9052 KB Output isn't correct
43 Incorrect 41 ms 8912 KB Output isn't correct
44 Incorrect 34 ms 9052 KB Output isn't correct
45 Incorrect 36 ms 9052 KB Output isn't correct
46 Incorrect 52 ms 9188 KB Output isn't correct
47 Incorrect 62 ms 9052 KB Output isn't correct
48 Incorrect 41 ms 9208 KB Output isn't correct
49 Incorrect 63 ms 9308 KB Output isn't correct
50 Incorrect 73 ms 9308 KB Output isn't correct
51 Incorrect 49 ms 9308 KB Output isn't correct
52 Incorrect 70 ms 9288 KB Output isn't correct
53 Incorrect 93 ms 9668 KB Output isn't correct
54 Incorrect 64 ms 9300 KB Output isn't correct
55 Incorrect 83 ms 9412 KB Output isn't correct
56 Incorrect 121 ms 9336 KB Output isn't correct
57 Incorrect 65 ms 9640 KB Output isn't correct
58 Incorrect 96 ms 9564 KB Output isn't correct
59 Incorrect 86 ms 9564 KB Output isn't correct
60 Incorrect 73 ms 9564 KB Output isn't correct
61 Incorrect 117 ms 9768 KB Output isn't correct
62 Incorrect 157 ms 9556 KB Output isn't correct
63 Correct 104 ms 9564 KB Output is correct
64 Correct 177 ms 9776 KB Output is correct
65 Incorrect 158 ms 9672 KB Output isn't correct
66 Correct 128 ms 9564 KB Output is correct
67 Correct 101 ms 9564 KB Output is correct
68 Incorrect 43 ms 9812 KB Output isn't correct
69 Correct 53 ms 9820 KB Output is correct
70 Incorrect 37 ms 9724 KB Output isn't correct
71 Incorrect 34 ms 9676 KB Output isn't correct
72 Incorrect 34 ms 9812 KB Output isn't correct
73 Incorrect 59 ms 10076 KB Output isn't correct
74 Incorrect 156 ms 10068 KB Output isn't correct
75 Incorrect 96 ms 10332 KB Output isn't correct
76 Incorrect 86 ms 10068 KB Output isn't correct
77 Incorrect 125 ms 10068 KB Output isn't correct
78 Incorrect 123 ms 10068 KB Output isn't correct
79 Incorrect 158 ms 10068 KB Output isn't correct
80 Incorrect 114 ms 10068 KB Output isn't correct
81 Incorrect 106 ms 10068 KB Output isn't correct
82 Incorrect 88 ms 9940 KB Output isn't correct
83 Incorrect 124 ms 10064 KB Output isn't correct
84 Incorrect 169 ms 10076 KB Output isn't correct
85 Incorrect 104 ms 10076 KB Output isn't correct
86 Incorrect 113 ms 10068 KB Output isn't correct
87 Incorrect 115 ms 10084 KB Output isn't correct
88 Incorrect 121 ms 10016 KB Output isn't correct
89 Incorrect 147 ms 9812 KB Output isn't correct
90 Incorrect 146 ms 9916 KB Output isn't correct
91 Incorrect 146 ms 9820 KB Output isn't correct
92 Incorrect 162 ms 10000 KB Output isn't correct