답안 #482480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482480 2021-10-24T17:54:56 Z asdf1234coding Mecho (IOI09_mecho) C++14
95 / 100
178 ms 6372 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define MOD (ll) (1e9+7)
#define pii pair<int,int>
#define ff first
#define ss second

int n,s; 
pii start,finish;
string board[801];
vector<vector<int>> beedist(801, vector<int>(801, -1));
queue<pii> bees;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

bool inBounds(pii asdf) {
    int x=asdf.ff; int y=asdf.ss;
    return (x>=0 && x<n && y>=0 && y<n && board[x][y]!='T');
}

void beeDist() {
    while(!bees.empty()) {
        auto curr = bees.front(); bees.pop();
        for(int i=0; i<4; i++) {
            pii next = {curr.first+dx[i], curr.second+dy[i]};
            if(inBounds(next) && beedist[next.ff][next.ss] == -1) {
                beedist[next.ff][next.ss] = beedist[curr.ff][curr.ss] + s;
                bees.push(next);
            }
        }
    }
}

bool test(int delay) {
    vector<vector<int>> dist(801, vector<int>(801, -1));
    if(delay*s>=beedist[start.ff][start.ss]) {
        return false;
    }
    queue<pii> q; q.push(start);
    dist[start.ff][start.ss] = delay*s;
    while(!q.empty()) {
        auto curr = q.front(); q.pop();
        if(curr == finish) {
            return true;
        }
        for(int i=0; i<4; i++) {
            pii next = {curr.ff+dx[i], curr.ss+dy[i]};
            if(inBounds(next)&&((dist[curr.ff][curr.ss]+1)<beedist[next.ff][next.ss])&&dist[next.ff][next.ss]==-1) {
                dist[next.ff][next.ss] = dist[curr.ff][curr.ss]+1;
                q.push(next);
            }
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin>>n>>s;
    for(int i=0; i<n; i++) {
        cin>>board[i];
        for(int j=0; j<n; j++) {
            if(board[i][j] == 'M') {
                start.ff = i;
                start.ss = j;
            } else if (board[i][j] == 'D') {
                finish.ff = i;
                finish.ss = j;
            } else if (board[i][j] == 'H') {
                beedist[i][j] = 0;
                bees.push({i,j});
            }
        }
    }

    beeDist();
    // for(int i=0; i<n; i++) {
    //     for(int j=0; j<n; j++) {
    //         cout<<beedist[i][j]<<' ';
    //     }
    //     cout<<endl;
    // }
    // cout<<test(0)<<endl;
    // cout<<test(1)<<endl;
    // cout<<test(2)<<endl;
    // cout<<test(3)<<endl;

    beedist[finish.ff][finish.ss] = n*n*s;

    //binsearch :D
    int lo = -1; int hi = 2*n*n;
    while(hi-lo>1) {
        int mid = (lo+hi)>>1;
        if(test(mid)) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    cout<<lo<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5404 KB Output is correct
2 Correct 6 ms 5424 KB Output is correct
3 Correct 5 ms 5404 KB Output is correct
4 Correct 6 ms 5424 KB Output is correct
5 Correct 7 ms 5444 KB Output is correct
6 Correct 8 ms 5448 KB Output is correct
7 Correct 108 ms 6140 KB Output is correct
8 Correct 8 ms 5424 KB Output is correct
9 Correct 8 ms 5444 KB Output is correct
10 Correct 9 ms 5428 KB Output is correct
11 Correct 11 ms 5424 KB Output is correct
12 Incorrect 11 ms 5460 KB Output isn't correct
13 Correct 11 ms 5440 KB Output is correct
14 Correct 11 ms 5444 KB Output is correct
15 Correct 9 ms 5444 KB Output is correct
16 Correct 11 ms 5424 KB Output is correct
17 Correct 9 ms 5444 KB Output is correct
18 Correct 10 ms 5444 KB Output is correct
19 Correct 10 ms 5428 KB Output is correct
20 Correct 9 ms 5572 KB Output is correct
21 Correct 10 ms 5452 KB Output is correct
22 Correct 10 ms 5460 KB Output is correct
23 Correct 10 ms 5460 KB Output is correct
24 Correct 10 ms 5440 KB Output is correct
25 Correct 11 ms 5420 KB Output is correct
26 Correct 13 ms 5480 KB Output is correct
27 Correct 12 ms 5444 KB Output is correct
28 Correct 12 ms 5456 KB Output is correct
29 Correct 14 ms 5468 KB Output is correct
30 Correct 14 ms 5456 KB Output is correct
31 Correct 12 ms 5508 KB Output is correct
32 Correct 12 ms 5476 KB Output is correct
33 Correct 17 ms 5588 KB Output is correct
34 Correct 16 ms 5580 KB Output is correct
35 Correct 32 ms 5588 KB Output is correct
36 Correct 21 ms 5636 KB Output is correct
37 Correct 18 ms 5636 KB Output is correct
38 Correct 33 ms 5620 KB Output is correct
39 Correct 19 ms 5680 KB Output is correct
40 Correct 20 ms 5736 KB Output is correct
41 Correct 66 ms 5668 KB Output is correct
42 Correct 21 ms 5788 KB Output is correct
43 Correct 18 ms 5748 KB Output is correct
44 Correct 48 ms 5716 KB Output is correct
45 Correct 19 ms 5788 KB Output is correct
46 Correct 19 ms 5816 KB Output is correct
47 Correct 60 ms 5784 KB Output is correct
48 Correct 20 ms 5844 KB Output is correct
49 Correct 21 ms 5864 KB Output is correct
50 Correct 72 ms 5840 KB Output is correct
51 Correct 20 ms 5900 KB Output is correct
52 Correct 21 ms 5936 KB Output is correct
53 Correct 76 ms 5920 KB Output is correct
54 Correct 22 ms 5988 KB Output is correct
55 Correct 29 ms 5984 KB Output is correct
56 Correct 86 ms 5976 KB Output is correct
57 Correct 30 ms 6084 KB Output is correct
58 Correct 24 ms 6116 KB Output is correct
59 Correct 129 ms 6060 KB Output is correct
60 Correct 23 ms 6156 KB Output is correct
61 Correct 23 ms 6292 KB Output is correct
62 Correct 142 ms 6128 KB Output is correct
63 Correct 99 ms 6120 KB Output is correct
64 Correct 178 ms 6108 KB Output is correct
65 Correct 140 ms 6120 KB Output is correct
66 Correct 131 ms 6180 KB Output is correct
67 Correct 116 ms 6112 KB Output is correct
68 Correct 51 ms 6132 KB Output is correct
69 Correct 50 ms 6148 KB Output is correct
70 Correct 42 ms 6140 KB Output is correct
71 Correct 46 ms 6140 KB Output is correct
72 Correct 40 ms 6204 KB Output is correct
73 Correct 44 ms 6276 KB Output is correct
74 Correct 58 ms 6164 KB Output is correct
75 Correct 70 ms 6144 KB Output is correct
76 Correct 62 ms 6176 KB Output is correct
77 Correct 58 ms 6148 KB Output is correct
78 Correct 72 ms 6144 KB Output is correct
79 Correct 52 ms 6156 KB Output is correct
80 Correct 70 ms 6164 KB Output is correct
81 Correct 64 ms 6172 KB Output is correct
82 Correct 55 ms 6148 KB Output is correct
83 Correct 74 ms 6152 KB Output is correct
84 Correct 66 ms 6200 KB Output is correct
85 Correct 86 ms 6144 KB Output is correct
86 Correct 77 ms 6372 KB Output is correct
87 Correct 68 ms 6156 KB Output is correct
88 Correct 85 ms 6144 KB Output is correct
89 Correct 89 ms 6132 KB Output is correct
90 Correct 75 ms 6196 KB Output is correct
91 Correct 73 ms 6148 KB Output is correct
92 Correct 92 ms 6140 KB Output is correct