답안 #482479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482479 2021-10-24T17:51:56 Z asdf1234coding Mecho (IOI09_mecho) C++14
84 / 100
180 ms 6844 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;

    //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 6 ms 5404 KB Output is correct
2 Incorrect 6 ms 5404 KB Output isn't correct
3 Correct 5 ms 5404 KB Output is correct
4 Incorrect 6 ms 5424 KB Output isn't correct
5 Correct 7 ms 5436 KB Output is correct
6 Incorrect 7 ms 5444 KB Output isn't correct
7 Incorrect 90 ms 6748 KB Output isn't correct
8 Correct 7 ms 5452 KB Output is correct
9 Correct 8 ms 5424 KB Output is correct
10 Correct 8 ms 5432 KB Output is correct
11 Correct 7 ms 5440 KB Output is correct
12 Incorrect 10 ms 5444 KB Output isn't correct
13 Correct 10 ms 5444 KB Output is correct
14 Correct 11 ms 5460 KB Output is correct
15 Correct 11 ms 5436 KB Output is correct
16 Correct 11 ms 5444 KB Output is correct
17 Correct 11 ms 5444 KB Output is correct
18 Correct 10 ms 5508 KB Output is correct
19 Correct 11 ms 5484 KB Output is correct
20 Correct 9 ms 5444 KB Output is correct
21 Correct 10 ms 5448 KB Output is correct
22 Correct 12 ms 5444 KB Output is correct
23 Correct 11 ms 5448 KB Output is correct
24 Correct 10 ms 5428 KB Output is correct
25 Correct 16 ms 5460 KB Output is correct
26 Correct 13 ms 5448 KB Output is correct
27 Correct 12 ms 5504 KB Output is correct
28 Correct 12 ms 5456 KB Output is correct
29 Correct 12 ms 5452 KB Output is correct
30 Correct 12 ms 5460 KB Output is correct
31 Correct 15 ms 5476 KB Output is correct
32 Correct 12 ms 5448 KB Output is correct
33 Correct 16 ms 5736 KB Output is correct
34 Correct 21 ms 5720 KB Output is correct
35 Correct 28 ms 5720 KB Output is correct
36 Correct 17 ms 5812 KB Output is correct
37 Correct 17 ms 5784 KB Output is correct
38 Correct 32 ms 5852 KB Output is correct
39 Correct 17 ms 5884 KB Output is correct
40 Correct 17 ms 5896 KB Output is correct
41 Correct 39 ms 5880 KB Output is correct
42 Correct 18 ms 5976 KB Output is correct
43 Correct 19 ms 5988 KB Output is correct
44 Correct 58 ms 6016 KB Output is correct
45 Correct 26 ms 6092 KB Output is correct
46 Correct 19 ms 6064 KB Output is correct
47 Correct 52 ms 6128 KB Output is correct
48 Correct 23 ms 6216 KB Output is correct
49 Correct 20 ms 6200 KB Output is correct
50 Correct 63 ms 6200 KB Output is correct
51 Correct 21 ms 6344 KB Output is correct
52 Correct 23 ms 6340 KB Output is correct
53 Correct 127 ms 6344 KB Output is correct
54 Correct 25 ms 6440 KB Output is correct
55 Correct 21 ms 6444 KB Output is correct
56 Correct 80 ms 6428 KB Output is correct
57 Correct 22 ms 6656 KB Output is correct
58 Correct 21 ms 6620 KB Output is correct
59 Correct 100 ms 6604 KB Output is correct
60 Correct 24 ms 6768 KB Output is correct
61 Correct 25 ms 6756 KB Output is correct
62 Correct 110 ms 6752 KB Output is correct
63 Correct 101 ms 6732 KB Output is correct
64 Correct 180 ms 6736 KB Output is correct
65 Correct 141 ms 6732 KB Output is correct
66 Correct 127 ms 6832 KB Output is correct
67 Correct 108 ms 6728 KB Output is correct
68 Correct 50 ms 6780 KB Output is correct
69 Correct 52 ms 6820 KB Output is correct
70 Correct 43 ms 6812 KB Output is correct
71 Correct 46 ms 6760 KB Output is correct
72 Correct 41 ms 6784 KB Output is correct
73 Correct 36 ms 6796 KB Output is correct
74 Correct 54 ms 6800 KB Output is correct
75 Correct 64 ms 6768 KB Output is correct
76 Correct 57 ms 6784 KB Output is correct
77 Correct 56 ms 6788 KB Output is correct
78 Correct 79 ms 6792 KB Output is correct
79 Correct 51 ms 6808 KB Output is correct
80 Correct 58 ms 6760 KB Output is correct
81 Correct 79 ms 6796 KB Output is correct
82 Correct 55 ms 6844 KB Output is correct
83 Correct 71 ms 6792 KB Output is correct
84 Correct 63 ms 6792 KB Output is correct
85 Correct 82 ms 6788 KB Output is correct
86 Correct 68 ms 6804 KB Output is correct
87 Correct 68 ms 6760 KB Output is correct
88 Correct 80 ms 6764 KB Output is correct
89 Correct 79 ms 6784 KB Output is correct
90 Correct 91 ms 6756 KB Output is correct
91 Correct 79 ms 6748 KB Output is correct
92 Correct 79 ms 6764 KB Output is correct