답안 #1100132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100132 2024-10-12T21:49:35 Z egccge Mecho (IOI09_mecho) C++17
84 / 100
146 ms 9564 KB
#include <bits/stdc++.h>
using namespace std;

int n, s, mx, my, ex, ey;
const int MAXN = 807;
char grid[MAXN][MAXN];
int bees[MAXN][MAXN];
int mecho[MAXN][MAXN];
int visited[MAXN][MAXN];
int d1[] = {0, 1, 0, -1};
int d2[] = {1, 0, -1, 0};

bool valid(int dx, int dy){
    return dx >= 0 && dx < n && dy >= 0 && dy < n && (grid[dx][dy] == 'G' || grid[dx][dy] == 'M');
}

bool chega(int m, int b){
    return ((m/s) < b);
}

bool check(int d){

    if(bees[mx][my] < d) return false;

    queue<pair<int, int>> pq;
    pq.push({mx, my});

    //reset
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            visited[i][j] = 0;
            mecho[i][j] = 0;
        }
    }
    

    while(!pq.empty()){
        auto [i, j] = pq.front(); pq.pop();
        for(int x = 0; x < 4; x++){
            int dx = d1[x] + i;
            int dy = d2[x] + j;
            if(valid(dx, dy) && !visited[dx][dy] && chega(mecho[i][j] + 1, bees[dx][dy] - d)){
                mecho[dx][dy] = mecho[i][j] + 1;
                visited[dx][dy] = 1;
                pq.push({dx, dy});
            }
        }
    }


    // cout << "mecho here" << endl;
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < n; j++){
    //         cout << mecho[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    bool res = false;
    for(int i = 0; i < 4; i++){
        int dx = d1[i] + ex;
        int dy = d2[i] + ey;
        if(valid(dx, dy) && chega(mecho[dx][dy], bees[dx][dy]) && visited[dx][dy]){
            res = true;
        }
    }
    return res;
}

int main(){
    cin >> n >> s;
    vector<pair<int, int>> h;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> grid[i][j];
            if(grid[i][j] == 'H')
                h.push_back({i, j});
            else if(grid[i][j] == 'M'){
                mx = i;
                my = j;
            }else if(grid[i][j] == 'D'){
                ex = i;
                ey = j;
            }

        }
    }

     //bfs para bees
    //t, i, j
    queue<pair<int, int>> pq;
    for(auto u : h)  pq.push({u.first, u.second});
    
    //funcionando o bfs para as abelhas!!
    while(!pq.empty()){
        auto [i, j] = pq.front();
        pq.pop();
        for(int x = 0; x < 4; x++){
            int dx = d1[x] + i;
            int dy = d2[x] + j;
            if(valid(dx, dy) && !bees[dx][dy]){
                bees[dx][dy] = bees[i][j] + 1;
                pq.push({dx, dy});
            }
        }
    }


    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < n; j++){
    //         cout << bees[i][j] << " ";
    //     }
    //     cout << endl;
    // }


    int l = 0, r = n*n; 
    while(l <= r){
        //cout << l << " " << r << endl;
        int mid = (l+r)/2;
        if(check(mid)) l = mid+1;
        else r = mid-1;
    }

    cout << l-1 << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 72 ms 9348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Incorrect 1 ms 860 KB Output isn't correct
13 Incorrect 1 ms 956 KB Output isn't correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 1 ms 860 KB Output is correct
23 Correct 1 ms 860 KB Output is correct
24 Correct 0 ms 860 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 1 ms 952 KB Output is correct
27 Correct 1 ms 1116 KB Output is correct
28 Correct 1 ms 968 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 8 ms 4128 KB Output is correct
34 Correct 8 ms 3928 KB Output is correct
35 Correct 18 ms 3932 KB Output is correct
36 Correct 9 ms 4684 KB Output is correct
37 Correct 10 ms 4700 KB Output is correct
38 Correct 24 ms 4696 KB Output is correct
39 Correct 11 ms 5212 KB Output is correct
40 Correct 12 ms 5076 KB Output is correct
41 Correct 36 ms 5244 KB Output is correct
42 Correct 16 ms 5720 KB Output is correct
43 Correct 19 ms 5848 KB Output is correct
44 Correct 47 ms 5816 KB Output is correct
45 Correct 15 ms 6232 KB Output is correct
46 Correct 17 ms 6236 KB Output is correct
47 Correct 43 ms 6228 KB Output is correct
48 Correct 20 ms 6744 KB Output is correct
49 Correct 22 ms 6744 KB Output is correct
50 Correct 53 ms 6748 KB Output is correct
51 Correct 21 ms 7516 KB Output is correct
52 Correct 24 ms 7512 KB Output is correct
53 Correct 72 ms 7516 KB Output is correct
54 Correct 34 ms 8076 KB Output is correct
55 Correct 26 ms 8024 KB Output is correct
56 Correct 72 ms 8028 KB Output is correct
57 Correct 30 ms 8528 KB Output is correct
58 Correct 28 ms 8532 KB Output is correct
59 Correct 83 ms 8540 KB Output is correct
60 Correct 30 ms 9052 KB Output is correct
61 Correct 31 ms 9052 KB Output is correct
62 Correct 93 ms 9052 KB Output is correct
63 Correct 87 ms 9040 KB Output is correct
64 Correct 146 ms 9048 KB Output is correct
65 Correct 113 ms 9040 KB Output is correct
66 Correct 95 ms 9052 KB Output is correct
67 Correct 95 ms 9280 KB Output is correct
68 Correct 62 ms 9296 KB Output is correct
69 Correct 51 ms 9040 KB Output is correct
70 Correct 42 ms 9308 KB Output is correct
71 Correct 46 ms 9120 KB Output is correct
72 Incorrect 38 ms 9044 KB Output isn't correct
73 Incorrect 41 ms 9552 KB Output isn't correct
74 Correct 62 ms 9388 KB Output is correct
75 Correct 66 ms 9556 KB Output is correct
76 Correct 60 ms 9556 KB Output is correct
77 Correct 61 ms 9564 KB Output is correct
78 Correct 73 ms 9304 KB Output is correct
79 Correct 57 ms 9296 KB Output is correct
80 Correct 57 ms 9524 KB Output is correct
81 Correct 63 ms 9308 KB Output is correct
82 Correct 57 ms 9296 KB Output is correct
83 Correct 69 ms 9244 KB Output is correct
84 Correct 64 ms 9296 KB Output is correct
85 Correct 70 ms 9296 KB Output is correct
86 Correct 72 ms 9464 KB Output is correct
87 Correct 74 ms 9308 KB Output is correct
88 Correct 73 ms 9296 KB Output is correct
89 Correct 70 ms 9296 KB Output is correct
90 Correct 72 ms 9300 KB Output is correct
91 Correct 69 ms 9300 KB Output is correct
92 Correct 80 ms 9300 KB Output is correct