Submission #1039368

# Submission time Handle Problem Language Result Execution time Memory
1039368 2024-07-30T19:15:16 Z Ludissey Mecho (IOI09_mecho) C++17
84 / 100
399 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,1e14));
    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((dist[x][y])/S>=beeT[x][y]&&grid[x][y]!='D') continue;
        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]){
            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]){
            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]){
            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]){
            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,1e14));
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 286 ms 12356 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 1 ms 348 KB Output isn't correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 13 ms 2692 KB Output is correct
34 Correct 13 ms 2800 KB Output is correct
35 Correct 65 ms 2732 KB Output is correct
36 Correct 20 ms 3448 KB Output is correct
37 Correct 15 ms 3452 KB Output is correct
38 Correct 86 ms 3412 KB Output is correct
39 Correct 18 ms 4480 KB Output is correct
40 Correct 19 ms 4124 KB Output is correct
41 Correct 107 ms 4136 KB Output is correct
42 Correct 24 ms 4976 KB Output is correct
43 Correct 25 ms 5104 KB Output is correct
44 Correct 146 ms 5088 KB Output is correct
45 Correct 28 ms 5996 KB Output is correct
46 Correct 30 ms 6004 KB Output is correct
47 Correct 174 ms 5972 KB Output is correct
48 Correct 35 ms 7008 KB Output is correct
49 Correct 44 ms 7156 KB Output is correct
50 Correct 222 ms 7032 KB Output is correct
51 Correct 39 ms 8128 KB Output is correct
52 Correct 44 ms 8196 KB Output is correct
53 Correct 254 ms 8160 KB Output is correct
54 Correct 59 ms 9484 KB Output is correct
55 Correct 56 ms 9452 KB Output is correct
56 Correct 292 ms 9368 KB Output is correct
57 Correct 57 ms 10676 KB Output is correct
58 Correct 59 ms 10704 KB Output is correct
59 Correct 353 ms 10728 KB Output is correct
60 Correct 61 ms 12128 KB Output is correct
61 Correct 66 ms 12096 KB Output is correct
62 Correct 399 ms 12084 KB Output is correct
63 Correct 215 ms 12020 KB Output is correct
64 Correct 387 ms 12092 KB Output is correct
65 Correct 340 ms 12024 KB Output is correct
66 Correct 248 ms 12092 KB Output is correct
67 Incorrect 242 ms 12052 KB Output isn't correct
68 Correct 128 ms 12160 KB Output is correct
69 Correct 132 ms 12168 KB Output is correct
70 Correct 127 ms 12228 KB Output is correct
71 Correct 102 ms 12096 KB Output is correct
72 Correct 105 ms 12240 KB Output is correct
73 Correct 141 ms 12868 KB Output is correct
74 Correct 226 ms 12856 KB Output is correct
75 Correct 239 ms 12848 KB Output is correct
76 Correct 226 ms 12900 KB Output is correct
77 Correct 226 ms 12820 KB Output is correct
78 Incorrect 258 ms 12872 KB Output isn't correct
79 Correct 217 ms 12720 KB Output is correct
80 Correct 229 ms 12860 KB Output is correct
81 Correct 235 ms 12776 KB Output is correct
82 Correct 209 ms 12744 KB Output is correct
83 Correct 252 ms 12768 KB Output is correct
84 Correct 261 ms 12644 KB Output is correct
85 Correct 234 ms 12696 KB Output is correct
86 Correct 277 ms 12624 KB Output is correct
87 Correct 274 ms 12836 KB Output is correct
88 Correct 245 ms 12556 KB Output is correct
89 Correct 300 ms 12560 KB Output is correct
90 Correct 281 ms 12532 KB Output is correct
91 Correct 278 ms 12556 KB Output is correct
92 Correct 306 ms 12560 KB Output is correct