답안 #934581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934581 2024-02-27T16:07:07 Z May27_th Mecho (IOI09_mecho) C++17
84 / 100
146 ms 7000 KB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;

void World_Final();
void Solve();

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    if (fopen(taskname".in", "r")) {
        freopen(taskname".in", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    World_Final();
}

void World_Final(){
    int Tests = 1;
    //cin >> Tests;
    while (Tests --) {
        Solve();
    }
}

const int MAXN = 805;
int N, S, bee[MAXN][MAXN], bear[MAXN][MAXN]; char G[MAXN][MAXN];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
pair<int, int> st, en;
bool query(int rest){
    memset(bear, -1, sizeof(bear));
    queue<pair<int, int>> q; q.push(st); bear[st.first][st.second] = 0;
    while (!q.empty()) {
        int u, v; tie(u, v) = q.front();
        //cout << u << " " << v << "\n";
        q.pop();
        for (int i = 0; i < 4; i ++) {
            int nu = u + dx[i];
            int nv = v + dy[i];
            if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) {
                if (G[nu][nv] == 'G' && bear[nu][nv] == -1) {
                    int t = (bear[u][v] + 1)/S;
                    if (t < bee[nu][nv] - rest) {
                        bear[nu][nv] = bear[u][v] + 1;
                        q.push(make_pair(nu, nv));
                    }
                }
                if (G[nu][nv] == 'D' && bear[nu][nv] == -1) {
                    bear[nu][nv] = bear[u][v] + 1;
                    q.push(make_pair(nu, nv));
                }
            }
        }
    }
    if (bear[en.first][en.second] != -1) return true;
    return false;

}
void Solve(){
    cin >> N >> S;
    for (int i = 1; i <= N; i ++) {
        for (int j = 1; j <= N; j ++) {
            cin >> G[i][j];
        }
    }

    memset(bee, -1, sizeof(bee)); queue<pair<int, int>> q;
    for (int i = 1; i <= N; i ++) {
        for (int j = 1; j <= N; j ++) {
            if (G[i][j] == 'H') {
                bee[i][j] = 0;
                q.push(make_pair(i, j));
            }
            if (G[i][j] == 'M') st = make_pair(i, j);
            if (G[i][j] == 'D') en = make_pair(i, j);
        }
    }
    while (!q.empty()) {
        int u, v; tie(u, v) = q.front();
        q.pop();
        for (int i = 0; i < 4; i ++) {
            int nu = u + dx[i];
            int nv = v + dy[i];
            if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) {
                if ((G[nu][nv] == 'G' || G[nu][nv] == 'M') && bee[nu][nv] == -1) {
                    bee[nu][nv] = bee[u][v] + 1;
                    q.push(make_pair(nu, nv));
                }
            }
        }
    }
    //cout << bee[en.first][en.second] << "\n";
    //cout << query(2);
    int l = 0, h = N * N;
    while (l <= h) {
        int mid = (l + h) / 2;
        //cout << mid << "\n";
        if (query(mid)) l = mid + 1;
        else h = mid - 1;
    } cout << h;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen(taskname".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5984 KB Output is correct
2 Correct 2 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 61 ms 6308 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Incorrect 2 ms 5980 KB Output isn't correct
13 Incorrect 2 ms 5980 KB Output isn't correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 2 ms 6004 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 2 ms 6232 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 5980 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Correct 2 ms 6232 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 2 ms 5980 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct
26 Correct 2 ms 5980 KB Output is correct
27 Correct 2 ms 5980 KB Output is correct
28 Correct 2 ms 5976 KB Output is correct
29 Correct 2 ms 5980 KB Output is correct
30 Correct 2 ms 5980 KB Output is correct
31 Correct 2 ms 5988 KB Output is correct
32 Correct 3 ms 5980 KB Output is correct
33 Correct 5 ms 6224 KB Output is correct
34 Correct 5 ms 6232 KB Output is correct
35 Correct 19 ms 6192 KB Output is correct
36 Correct 6 ms 6236 KB Output is correct
37 Correct 6 ms 6236 KB Output is correct
38 Correct 24 ms 6208 KB Output is correct
39 Correct 7 ms 6284 KB Output is correct
40 Correct 7 ms 6236 KB Output is correct
41 Correct 33 ms 6292 KB Output is correct
42 Correct 8 ms 6236 KB Output is correct
43 Correct 9 ms 6232 KB Output is correct
44 Correct 39 ms 6236 KB Output is correct
45 Correct 9 ms 6232 KB Output is correct
46 Correct 10 ms 6236 KB Output is correct
47 Correct 40 ms 6236 KB Output is correct
48 Correct 10 ms 6236 KB Output is correct
49 Correct 11 ms 6368 KB Output is correct
50 Correct 55 ms 6232 KB Output is correct
51 Correct 12 ms 6452 KB Output is correct
52 Correct 13 ms 6232 KB Output is correct
53 Correct 66 ms 6460 KB Output is correct
54 Correct 13 ms 6236 KB Output is correct
55 Correct 14 ms 6492 KB Output is correct
56 Correct 68 ms 6236 KB Output is correct
57 Correct 18 ms 6232 KB Output is correct
58 Correct 16 ms 6492 KB Output is correct
59 Correct 79 ms 6500 KB Output is correct
60 Correct 16 ms 6480 KB Output is correct
61 Correct 18 ms 6488 KB Output is correct
62 Correct 88 ms 6424 KB Output is correct
63 Correct 86 ms 6536 KB Output is correct
64 Correct 146 ms 6496 KB Output is correct
65 Correct 121 ms 6736 KB Output is correct
66 Correct 92 ms 6516 KB Output is correct
67 Correct 86 ms 6488 KB Output is correct
68 Correct 37 ms 6432 KB Output is correct
69 Correct 40 ms 6484 KB Output is correct
70 Correct 29 ms 6492 KB Output is correct
71 Correct 33 ms 6600 KB Output is correct
72 Incorrect 24 ms 6492 KB Output isn't correct
73 Incorrect 31 ms 6744 KB Output isn't correct
74 Correct 43 ms 6824 KB Output is correct
75 Correct 58 ms 6748 KB Output is correct
76 Correct 46 ms 6748 KB Output is correct
77 Correct 51 ms 6748 KB Output is correct
78 Correct 60 ms 6748 KB Output is correct
79 Correct 36 ms 6748 KB Output is correct
80 Correct 48 ms 6752 KB Output is correct
81 Correct 49 ms 6764 KB Output is correct
82 Correct 50 ms 7000 KB Output is correct
83 Correct 57 ms 6744 KB Output is correct
84 Correct 54 ms 6488 KB Output is correct
85 Correct 61 ms 6748 KB Output is correct
86 Correct 54 ms 6780 KB Output is correct
87 Correct 61 ms 6776 KB Output is correct
88 Correct 64 ms 6748 KB Output is correct
89 Correct 58 ms 6688 KB Output is correct
90 Correct 60 ms 6744 KB Output is correct
91 Correct 65 ms 6492 KB Output is correct
92 Correct 64 ms 6964 KB Output is correct