답안 #777102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777102 2023-07-08T16:36:32 Z Surver Mecho (IOI09_mecho) C++17
35 / 100
177 ms 6248 KB
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,s;
    cin>>n>>s;
    vector<string> v(n);
    for (int i=0;i<n;i++){
        cin>>v[i];
    }   
    int inf=(int)1e5;
    vector<vector<int>> dis(n,vector<int>(n,inf));
    queue<pair<int,int>> q;
    pair<int,int> start={-1,-1};
    pair<int,int> end={-1,-1};
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            if (v[i][j]=='H'){
                q.push({i,j});
                dis[i][j]=0;
            }
            if (v[i][j]=='M'){
                start={i,j};
            }
            if (v[i][j]=='D'){
                end={i,j};
            }
        }
    }
    auto valid = [&] (int x,int y){
        return x>=0 && x<n && y>=0 && y<n;
    };
    vector<int> dx={0,-1,0,1};
    vector<int> dy={-1,0,1,0};
    while(!q.empty()){
        auto [x,y]=q.front();
        q.pop();
        for (int i=0;i<4;i++){
            if (valid(x+dx[i],y+dy[i]) && dis[x+dx[i]][y+dy[i]]==inf){
                if (v[x+dx[i]][y+dy[i]]=='G'){
                    dis[x+dx[i]][y+dy[i]]=1+dis[x][y];
                    q.push({x+dx[i],y+dy[i]});
                }
                if (v[x+dx[i]][y+dy[i]]=='M'){
                    dis[x+dx[i]][y+dy[i]]=1+dis[x][y];
                }
            }
        }
    }
    int low=0,high=inf;
    int ans=-1;
    while(low<=high){
        int mid=(low+high)/2;
        vector<vector<int>> dis2(n,vector<int>(n,inf));
        q.push(start);
        if (mid>=dis[start.first][start.second]){
            q.pop();
        }
        dis2[start.first][start.second]=mid*s;
        while(!q.empty()){
            auto [x,y]=q.front();
            q.pop();
            for (int i=0;i<4;i++){
                if (valid(x+dx[i],y+dy[i])){
                    if ((dis2[x][y]+1)/s<dis[x+dx[i]][y+dy[i]] && dis2[x+dx[i]][y+dy[i]]==inf){
                        dis2[x+dx[i]][y+dy[i]]=1+dis2[x][y];
                        q.push({x+dx[i],y+dy[i]});
                    }
                }
            }
        }
        if (dis2[end.first][end.second]==inf){
            high=mid-1;
        }
        else{
            ans=max(ans,mid);
            low=mid+1;
        }
    }
    cout<<ans<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 83 ms 6124 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Correct 1 ms 212 KB Output is correct
16 Incorrect 1 ms 212 KB Output isn't correct
17 Correct 0 ms 212 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Correct 0 ms 340 KB Output is correct
22 Incorrect 1 ms 212 KB Output isn't correct
23 Correct 1 ms 340 KB Output is correct
24 Incorrect 1 ms 340 KB Output isn't correct
25 Correct 0 ms 340 KB Output is correct
26 Incorrect 1 ms 276 KB Output isn't correct
27 Correct 1 ms 340 KB Output is correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Correct 1 ms 340 KB Output is correct
30 Incorrect 1 ms 340 KB Output isn't correct
31 Correct 1 ms 340 KB Output is correct
32 Incorrect 1 ms 340 KB Output isn't correct
33 Correct 5 ms 1428 KB Output is correct
34 Incorrect 10 ms 1432 KB Output isn't correct
35 Incorrect 22 ms 1444 KB Output isn't correct
36 Correct 7 ms 1748 KB Output is correct
37 Incorrect 14 ms 1860 KB Output isn't correct
38 Incorrect 42 ms 2052 KB Output isn't correct
39 Incorrect 12 ms 2156 KB Output isn't correct
40 Incorrect 27 ms 2160 KB Output isn't correct
41 Incorrect 41 ms 2184 KB Output isn't correct
42 Incorrect 28 ms 2616 KB Output isn't correct
43 Incorrect 27 ms 2664 KB Output isn't correct
44 Incorrect 53 ms 2592 KB Output isn't correct
45 Incorrect 45 ms 3076 KB Output isn't correct
46 Incorrect 43 ms 3084 KB Output isn't correct
47 Incorrect 61 ms 3076 KB Output isn't correct
48 Incorrect 64 ms 3648 KB Output isn't correct
49 Incorrect 43 ms 3568 KB Output isn't correct
50 Incorrect 73 ms 3608 KB Output isn't correct
51 Incorrect 81 ms 4132 KB Output isn't correct
52 Incorrect 72 ms 4112 KB Output isn't correct
53 Incorrect 87 ms 4156 KB Output isn't correct
54 Incorrect 102 ms 4740 KB Output isn't correct
55 Incorrect 111 ms 4748 KB Output isn't correct
56 Incorrect 101 ms 4780 KB Output isn't correct
57 Incorrect 123 ms 5392 KB Output isn't correct
58 Incorrect 147 ms 5444 KB Output isn't correct
59 Incorrect 121 ms 5420 KB Output isn't correct
60 Incorrect 144 ms 6092 KB Output isn't correct
61 Incorrect 177 ms 6092 KB Output isn't correct
62 Incorrect 145 ms 6116 KB Output isn't correct
63 Incorrect 34 ms 6160 KB Output isn't correct
64 Incorrect 39 ms 6116 KB Output isn't correct
65 Incorrect 36 ms 6136 KB Output isn't correct
66 Incorrect 32 ms 6120 KB Output isn't correct
67 Incorrect 40 ms 6124 KB Output isn't correct
68 Incorrect 30 ms 6140 KB Output isn't correct
69 Incorrect 34 ms 6140 KB Output isn't correct
70 Incorrect 35 ms 6136 KB Output isn't correct
71 Incorrect 34 ms 6136 KB Output isn't correct
72 Correct 29 ms 6148 KB Output is correct
73 Correct 38 ms 6156 KB Output is correct
74 Incorrect 26 ms 6168 KB Output isn't correct
75 Incorrect 26 ms 6136 KB Output isn't correct
76 Incorrect 27 ms 6152 KB Output isn't correct
77 Incorrect 26 ms 6156 KB Output isn't correct
78 Incorrect 25 ms 6132 KB Output isn't correct
79 Incorrect 26 ms 6152 KB Output isn't correct
80 Incorrect 28 ms 6164 KB Output isn't correct
81 Incorrect 26 ms 6164 KB Output isn't correct
82 Incorrect 25 ms 6148 KB Output isn't correct
83 Incorrect 25 ms 6148 KB Output isn't correct
84 Incorrect 25 ms 6164 KB Output isn't correct
85 Incorrect 38 ms 6160 KB Output isn't correct
86 Incorrect 25 ms 6172 KB Output isn't correct
87 Incorrect 25 ms 6140 KB Output isn't correct
88 Incorrect 26 ms 6148 KB Output isn't correct
89 Incorrect 47 ms 6248 KB Output isn't correct
90 Incorrect 25 ms 6148 KB Output isn't correct
91 Incorrect 26 ms 6204 KB Output isn't correct
92 Incorrect 25 ms 6188 KB Output isn't correct