Submission #1078903

# Submission time Handle Problem Language Result Execution time Memory
1078903 2024-08-28T07:55:59 Z Yang8on Mecho (IOI09_mecho) C++17
5 / 100
213 ms 65536 KB
#include <bits/stdc++.h>
#define Y8o "main"
#define maxn (int) 805
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r

#define f first
#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

int n, S;
pii st, en;
char a[maxn][maxn];
int lim[maxn][maxn], dp[maxn][maxn];
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
bool exist(int u, int v) { return 1 <= u && u <= n && 1 <= v && v <= n && a[u][v] != 'T'; }

bool check(int tg) {
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++)
        dp[i][j] = 1e9;
    dp[st.f][st.s] = tg * S;

    queue<pii> q;
    q.push(st);
    while(q.size()) {
        int i, j; tie(i, j) = q.front();
        q.pop();
        for(int t = 0; t <= 3; t ++) {
            int u = i + dx[t], v = j + dy[t];
            if(exist(u, v) && dp[i][j] + 1 < lim[u][v]) {
                dp[u][v] = dp[i][j] + 1;
                q.push({ u, v });
            }
        }
    }
    return dp[en.f][en.s] < lim[en.f][en.s];
}

void solve() {
    cin >> n >> S;
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) {
        cin >> a[i][j];
        if(a[i][j] == 'M') st = {i, j};
        else if(a[i][j] == 'D') en = {i, j};
    }

    queue<pii> q;
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) {
        lim[i][j] = 1e9;
        if(a[i][j] == 'H') lim[i][j] = 0, q.push({ i, j });
    }
    while(q.size()) {
        int i, j; tie(i, j) = q.front();
        q.pop();
        for(int t = 0; t <= 3; t ++) {
            int u = i + dx[t], v = j + dy[t];
            if(exist(u, v)) {
                if(lim[u][v] > lim[i][j] + S) {
                    lim[u][v] = lim[i][j] + S;
                    q.push({ u, v });
                }
            }
        }
    }

    int l = 1, r = n * n;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    cout << r;
}

int main() {
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

mecho.cpp: In function 'void iof()':
mecho.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 55 ms 7580 KB Output isn't correct
7 Runtime error 144 ms 65536 KB Execution killed with signal 9
8 Incorrect 1 ms 348 KB Output isn't correct
9 Runtime error 172 ms 65536 KB Execution killed with signal 9
10 Correct 3 ms 856 KB Output is correct
11 Runtime error 143 ms 65536 KB Execution killed with signal 9
12 Incorrect 1 ms 856 KB Output isn't correct
13 Runtime error 126 ms 65536 KB Execution killed with signal 9
14 Runtime error 143 ms 65536 KB Execution killed with signal 9
15 Runtime error 192 ms 65536 KB Execution killed with signal 9
16 Runtime error 174 ms 65536 KB Execution killed with signal 9
17 Runtime error 173 ms 65536 KB Execution killed with signal 9
18 Runtime error 187 ms 65536 KB Execution killed with signal 9
19 Runtime error 176 ms 65536 KB Execution killed with signal 9
20 Runtime error 181 ms 65536 KB Execution killed with signal 9
21 Runtime error 176 ms 65536 KB Execution killed with signal 9
22 Runtime error 184 ms 65536 KB Execution killed with signal 9
23 Runtime error 185 ms 65536 KB Execution killed with signal 9
24 Runtime error 185 ms 65536 KB Execution killed with signal 9
25 Runtime error 182 ms 65536 KB Execution killed with signal 9
26 Runtime error 191 ms 65536 KB Execution killed with signal 9
27 Runtime error 174 ms 65536 KB Execution killed with signal 9
28 Runtime error 176 ms 65536 KB Execution killed with signal 9
29 Runtime error 180 ms 65536 KB Execution killed with signal 9
30 Runtime error 201 ms 65536 KB Execution killed with signal 9
31 Runtime error 178 ms 65536 KB Execution killed with signal 9
32 Runtime error 182 ms 65536 KB Execution killed with signal 9
33 Runtime error 176 ms 65536 KB Execution killed with signal 9
34 Runtime error 166 ms 65536 KB Execution killed with signal 9
35 Runtime error 166 ms 65536 KB Execution killed with signal 9
36 Runtime error 170 ms 65536 KB Execution killed with signal 9
37 Runtime error 164 ms 65536 KB Execution killed with signal 9
38 Runtime error 165 ms 65536 KB Execution killed with signal 9
39 Runtime error 166 ms 65536 KB Execution killed with signal 9
40 Runtime error 165 ms 65536 KB Execution killed with signal 9
41 Runtime error 182 ms 65536 KB Execution killed with signal 9
42 Runtime error 176 ms 65536 KB Execution killed with signal 9
43 Runtime error 169 ms 65536 KB Execution killed with signal 9
44 Runtime error 189 ms 65536 KB Execution killed with signal 9
45 Runtime error 173 ms 65536 KB Execution killed with signal 9
46 Runtime error 167 ms 65536 KB Execution killed with signal 9
47 Runtime error 174 ms 65536 KB Execution killed with signal 9
48 Runtime error 173 ms 65536 KB Execution killed with signal 9
49 Runtime error 183 ms 65536 KB Execution killed with signal 9
50 Runtime error 166 ms 65536 KB Execution killed with signal 9
51 Runtime error 169 ms 65536 KB Execution killed with signal 9
52 Runtime error 165 ms 65536 KB Execution killed with signal 9
53 Runtime error 175 ms 65536 KB Execution killed with signal 9
54 Runtime error 164 ms 65536 KB Execution killed with signal 9
55 Runtime error 161 ms 65536 KB Execution killed with signal 9
56 Runtime error 169 ms 65536 KB Execution killed with signal 9
57 Runtime error 173 ms 65536 KB Execution killed with signal 9
58 Runtime error 160 ms 65536 KB Execution killed with signal 9
59 Runtime error 169 ms 65536 KB Execution killed with signal 9
60 Runtime error 170 ms 65536 KB Execution killed with signal 9
61 Runtime error 162 ms 65536 KB Execution killed with signal 9
62 Runtime error 170 ms 65536 KB Execution killed with signal 9
63 Runtime error 175 ms 65536 KB Execution killed with signal 9
64 Runtime error 165 ms 65536 KB Execution killed with signal 9
65 Runtime error 170 ms 65536 KB Execution killed with signal 9
66 Runtime error 175 ms 65536 KB Execution killed with signal 9
67 Runtime error 175 ms 65536 KB Execution killed with signal 9
68 Runtime error 192 ms 65536 KB Execution killed with signal 9
69 Runtime error 213 ms 65536 KB Execution killed with signal 9
70 Runtime error 207 ms 65536 KB Execution killed with signal 9
71 Runtime error 185 ms 65536 KB Execution killed with signal 9
72 Runtime error 176 ms 65536 KB Execution killed with signal 9
73 Runtime error 136 ms 65536 KB Execution killed with signal 9
74 Runtime error 133 ms 65536 KB Execution killed with signal 9
75 Runtime error 133 ms 65536 KB Execution killed with signal 9
76 Runtime error 134 ms 65536 KB Execution killed with signal 9
77 Runtime error 142 ms 65536 KB Execution killed with signal 9
78 Runtime error 129 ms 65536 KB Execution killed with signal 9
79 Runtime error 133 ms 65536 KB Execution killed with signal 9
80 Runtime error 128 ms 65536 KB Execution killed with signal 9
81 Runtime error 132 ms 65536 KB Execution killed with signal 9
82 Runtime error 139 ms 65536 KB Execution killed with signal 9
83 Runtime error 137 ms 65536 KB Execution killed with signal 9
84 Runtime error 166 ms 65536 KB Execution killed with signal 9
85 Runtime error 144 ms 65536 KB Execution killed with signal 9
86 Runtime error 140 ms 65536 KB Execution killed with signal 9
87 Runtime error 131 ms 65536 KB Execution killed with signal 9
88 Runtime error 137 ms 65536 KB Execution killed with signal 9
89 Runtime error 129 ms 65536 KB Execution killed with signal 9
90 Runtime error 139 ms 65536 KB Execution killed with signal 9
91 Runtime error 145 ms 65536 KB Execution killed with signal 9
92 Runtime error 141 ms 65536 KB Execution killed with signal 9