답안 #781004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781004 2023-07-12T15:32:47 Z canadavid1 Mecho (IOI09_mecho) C++14
100 / 100
244 ms 6784 KB
#include <bits/stdc++.h>

using namespace std;

struct Node
{
    bool g=true;
    int beesat=INT_MAX;
};
int N,S;
complex<int> start;
complex<int> end;
vector<vector<Node>> cell;

bool outOfRange(complex<int> a)
{
    return a.real() < 0 || a.real() >= N || a.imag() < 0 || a.imag() >= N;
}

template<typename T>
T& at(vector<vector<T>>& v,complex<int> p)
{
    return v[p.real()][p.imag()];
}

bool bfs(int m)
{
    queue<pair<complex<int>,int>> q;
    vector<vector<char>> seen(N,vector<char>(N,false));
    q.push({start,S*m});
    while(q.size())
    {
        auto a = q.front(); q.pop();
        if(at(seen,a.first)) continue;
        at(seen,a.first)=true;
        if(at(cell,a.first).beesat <= a.second) continue;
        if(a.first==::end) return true;
        for(auto i : initializer_list<complex<int>>{{1,0},{-1,0},{0,1},{0,-1}})
        {
            if(outOfRange(a.first+i)) continue;
            if(a.first+i!=::end&&!at(cell,a.first+i).g) continue;
            q.push({a.first+i,a.second+1});
        }
    }
    return false;
}


int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> N >> S;
    cell.assign(N,vector<Node>(N));
    queue<complex<int>> bees;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            char a;
            cin >> a;
            switch(a)
            {
            case 'D':
                ::end = {i,j};
            case 'T':
                cell[i][j].g = false;
                break;
            case 'M':
                start = {i,j};
                break;
            case 'H':
                cell[i][j].beesat = 0;
                bees.push({i,j});
            case 'G':
                ;
            }
        }
    }
    while(bees.size())
    {
        auto a = bees.front();bees.pop();
        for(complex<int> i : initializer_list<complex<int>>{{1,0},{-1,0},{0,1},{0,-1}})
        {
            auto b = a+i;
            if(outOfRange(b)) continue;
            if (!at(cell,b).g || at(cell,b).beesat < INT_MAX) continue;
            at(cell,b).beesat = at(cell,a).beesat+S;
            bees.push(b);
        }
    }
    int l = -1;
    int r = N*N;
    while(l < r-1)
    {
        int m = (l+r)/2;
        if (bfs(m))
            l = m;
        else
            r = m;
    }
    cout << l << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 368 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 139 ms 6784 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 5 ms 1492 KB Output is correct
34 Correct 5 ms 1540 KB Output is correct
35 Correct 38 ms 1504 KB Output is correct
36 Correct 6 ms 1904 KB Output is correct
37 Correct 6 ms 1876 KB Output is correct
38 Correct 46 ms 1916 KB Output is correct
39 Correct 7 ms 2340 KB Output is correct
40 Correct 8 ms 2360 KB Output is correct
41 Correct 51 ms 2332 KB Output is correct
42 Correct 9 ms 2804 KB Output is correct
43 Correct 7 ms 2796 KB Output is correct
44 Correct 80 ms 2836 KB Output is correct
45 Correct 11 ms 3304 KB Output is correct
46 Correct 11 ms 3316 KB Output is correct
47 Correct 93 ms 3328 KB Output is correct
48 Correct 13 ms 3880 KB Output is correct
49 Correct 13 ms 3820 KB Output is correct
50 Correct 112 ms 3860 KB Output is correct
51 Correct 10 ms 4528 KB Output is correct
52 Correct 11 ms 4508 KB Output is correct
53 Correct 121 ms 4520 KB Output is correct
54 Correct 17 ms 5164 KB Output is correct
55 Correct 12 ms 5108 KB Output is correct
56 Correct 130 ms 5188 KB Output is correct
57 Correct 16 ms 5872 KB Output is correct
58 Correct 14 ms 5844 KB Output is correct
59 Correct 200 ms 5892 KB Output is correct
60 Correct 16 ms 6648 KB Output is correct
61 Correct 16 ms 6644 KB Output is correct
62 Correct 207 ms 6684 KB Output is correct
63 Correct 118 ms 6644 KB Output is correct
64 Correct 244 ms 6644 KB Output is correct
65 Correct 189 ms 6644 KB Output is correct
66 Correct 138 ms 6672 KB Output is correct
67 Correct 148 ms 6640 KB Output is correct
68 Correct 69 ms 6532 KB Output is correct
69 Correct 65 ms 6620 KB Output is correct
70 Correct 45 ms 6604 KB Output is correct
71 Correct 55 ms 6644 KB Output is correct
72 Correct 35 ms 6572 KB Output is correct
73 Correct 35 ms 6668 KB Output is correct
74 Correct 82 ms 6664 KB Output is correct
75 Correct 106 ms 6660 KB Output is correct
76 Correct 108 ms 6712 KB Output is correct
77 Correct 93 ms 6660 KB Output is correct
78 Correct 125 ms 6664 KB Output is correct
79 Correct 64 ms 6660 KB Output is correct
80 Correct 84 ms 6680 KB Output is correct
81 Correct 132 ms 6664 KB Output is correct
82 Correct 84 ms 6660 KB Output is correct
83 Correct 118 ms 6668 KB Output is correct
84 Correct 102 ms 6696 KB Output is correct
85 Correct 146 ms 6712 KB Output is correct
86 Correct 148 ms 6672 KB Output is correct
87 Correct 148 ms 6664 KB Output is correct
88 Correct 148 ms 6668 KB Output is correct
89 Correct 124 ms 6664 KB Output is correct
90 Correct 167 ms 6692 KB Output is correct
91 Correct 139 ms 6676 KB Output is correct
92 Correct 149 ms 6696 KB Output is correct