답안 #1039344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039344 2024-07-30T18:40:15 Z Ludissey Mecho (IOI09_mecho) C++17
18 / 100
383 ms 12900 KB
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()

using namespace std;
vector<vector<bool>> visited;
vector<vector<int>> dist;

vector<vector<char>> grid;
vector<vector<int>> beeT;
pair<int,int> home;
pair<int,int> bear;
int N,S;
bool f(int t){
    priority_queue<pair<int,pair<int,int>>> q;
    visited.clear();
    dist.clear();
    visited.resize(N,vector<bool>(N,false));
    dist.resize(N,vector<int>(N,1e9));
    dist[bear.first][bear.second]=t*S;
    q.push({-t*S,bear});
    while(!q.empty()){
        int x=q.top().second.first,y=q.top().second.second; q.pop();
        if(visited[x][y]) continue;
        visited[x][y]=true;
        if(x-1>=0&&(grid[x-1][y]=='G'||grid[x-1][y]=='M'||grid[x-1][y]=='D')&&dist[x][y]+1<dist[x-1][y]){
            if((dist[x][y]+1)/S>=beeT[x][y]&&grid[x][y]!='D') continue;
            dist[x-1][y]=dist[x][y]+1;
            q.push({-dist[x-1][y], {x-1,y}});
        }
        if(x+1<N&&(grid[x+1][y]=='G'||grid[x+1][y]=='M'||grid[x+1][y]=='D')&&dist[x][y]+1<dist[x+1][y]){
            if((dist[x][y]+1)/S>=beeT[x][y]&&grid[x][y]!='D') continue;
            dist[x+1][y]=dist[x][y]+1;
            q.push({-dist[x+1][y], {x+1,y}});
        }
        if(y-1>=0&&(grid[x][y-1]=='G'||grid[x][y-1]=='M'||grid[x][y-1]=='D')&&dist[x][y]+1<dist[x][y-1]){
            if((dist[x][y]+1)/S>=beeT[x][y]&&grid[x][y]!='D') continue;
            dist[x][y-1]=dist[x][y]+1;
            q.push({-dist[x][y-1], {x,y-1}});
        }
        if(y+1<N&&(grid[x][y+1]=='G'||grid[x][y+1]=='M'||grid[x][y+1]=='D')&&dist[x][y]+1<dist[x][y+1]){
            if((dist[x][y]+1)/S>=beeT[x][y]&&grid[x][y]!='D') continue;
            dist[x][y+1]=dist[x][y]+1;
            q.push({-dist[x][y+1], {x,y+1}});
        }
    }
    return visited[home.first][home.second];
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> S;
    grid.resize(N,vector<char>(N));
    visited.resize(N,vector<bool>(N,false));
    for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) cin >> grid[i][j]; }
    for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++){
        if(grid[i][j]=='M') bear={i,j};
        else if(grid[i][j]=='D') home={i,j};
    } 
    }
    beeT.resize(N,vector<int>(N,1e9));
    priority_queue<pair<int,pair<int,int>>> q;
    for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) if(grid[i][j]=='H') { q.push({0,{i,j}}); beeT[i][j]=0; }}
    while(!q.empty()){
        int x=q.top().second.first,y=q.top().second.second; q.pop();
        if(visited[x][y]) continue;
        visited[x][y]=true;
        if(x-1>=0&&(grid[x-1][y]=='G'||grid[x-1][y]=='M')&&beeT[x][y]+1<beeT[x-1][y]){
            beeT[x-1][y]=beeT[x][y]+1;
            q.push({-beeT[x-1][y], {x-1,y}});
        }
        if(x+1<N&&(grid[x+1][y]=='G'||grid[x+1][y]=='M')&&beeT[x][y]+1<beeT[x+1][y]){
            beeT[x+1][y]=beeT[x][y]+1;
            q.push({-beeT[x+1][y], {x+1,y}});
        }
        if(y-1>=0&&(grid[x][y-1]=='G'||grid[x][y-1]=='M')&&beeT[x][y]+1<beeT[x][y-1]){
            beeT[x][y-1]=beeT[x][y]+1;
            q.push({-beeT[x][y-1], {x,y-1}});
        }
        if(y+1<N&&(grid[x][y+1]=='G'||grid[x][y+1]=='M')&&beeT[x][y]+1<beeT[x][y+1]){
            beeT[x][y+1]=beeT[x][y]+1;
            q.push({-beeT[x][y+1], {x,y+1}});
        }
    }
    int l=0,r=1e9;
    while(l<r){
        int mid=(l+r+1)/2;
        if(f(mid)){
            l=mid;
        }else{
            r=mid-1;
        }
    }
    cout << l << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Correct 294 ms 12328 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 1 ms 344 KB Output isn't correct
20 Correct 1 ms 348 KB Output is correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Correct 1 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Correct 1 ms 348 KB Output is correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Correct 1 ms 344 KB Output is correct
27 Incorrect 1 ms 344 KB Output isn't correct
28 Correct 1 ms 348 KB Output is correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Correct 1 ms 348 KB Output is correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Correct 1 ms 348 KB Output is correct
33 Incorrect 12 ms 2692 KB Output isn't correct
34 Correct 14 ms 2692 KB Output is correct
35 Correct 63 ms 2772 KB Output is correct
36 Incorrect 14 ms 3360 KB Output isn't correct
37 Correct 15 ms 3360 KB Output is correct
38 Correct 82 ms 3380 KB Output is correct
39 Incorrect 18 ms 4120 KB Output isn't correct
40 Correct 24 ms 4220 KB Output is correct
41 Correct 104 ms 4192 KB Output is correct
42 Incorrect 24 ms 5036 KB Output isn't correct
43 Correct 25 ms 5104 KB Output is correct
44 Correct 143 ms 5040 KB Output is correct
45 Incorrect 28 ms 6016 KB Output isn't correct
46 Correct 36 ms 6220 KB Output is correct
47 Correct 174 ms 5972 KB Output is correct
48 Incorrect 35 ms 7176 KB Output isn't correct
49 Correct 38 ms 7028 KB Output is correct
50 Correct 210 ms 6984 KB Output is correct
51 Incorrect 43 ms 8124 KB Output isn't correct
52 Correct 43 ms 8120 KB Output is correct
53 Correct 240 ms 8136 KB Output is correct
54 Incorrect 52 ms 9356 KB Output isn't correct
55 Correct 56 ms 9372 KB Output is correct
56 Correct 290 ms 9404 KB Output is correct
57 Incorrect 52 ms 10748 KB Output isn't correct
58 Correct 57 ms 10704 KB Output is correct
59 Correct 346 ms 10720 KB Output is correct
60 Incorrect 60 ms 12080 KB Output isn't correct
61 Correct 61 ms 12036 KB Output is correct
62 Correct 374 ms 12016 KB Output is correct
63 Correct 223 ms 12156 KB Output is correct
64 Incorrect 383 ms 12092 KB Output isn't correct
65 Correct 357 ms 12108 KB Output is correct
66 Correct 260 ms 12092 KB Output is correct
67 Incorrect 262 ms 12116 KB Output isn't correct
68 Correct 128 ms 12268 KB Output is correct
69 Incorrect 126 ms 12176 KB Output isn't correct
70 Correct 125 ms 12184 KB Output is correct
71 Correct 106 ms 12120 KB Output is correct
72 Correct 106 ms 12092 KB Output is correct
73 Correct 150 ms 12900 KB Output is correct
74 Incorrect 239 ms 12832 KB Output isn't correct
75 Correct 246 ms 12840 KB Output is correct
76 Incorrect 227 ms 12852 KB Output isn't correct
77 Correct 230 ms 12852 KB Output is correct
78 Incorrect 265 ms 12784 KB Output isn't correct
79 Correct 227 ms 12768 KB Output is correct
80 Correct 230 ms 12788 KB Output is correct
81 Correct 245 ms 12784 KB Output is correct
82 Correct 230 ms 12812 KB Output is correct
83 Correct 264 ms 12644 KB Output is correct
84 Incorrect 262 ms 12616 KB Output isn't correct
85 Correct 262 ms 12672 KB Output is correct
86 Correct 268 ms 12748 KB Output is correct
87 Correct 283 ms 12704 KB Output is correct
88 Correct 266 ms 12552 KB Output is correct
89 Incorrect 294 ms 12584 KB Output isn't correct
90 Correct 290 ms 12520 KB Output is correct
91 Correct 298 ms 12552 KB Output is correct
92 Correct 290 ms 12580 KB Output is correct