Submission #1039362

# Submission time Handle Problem Language Result Execution time Memory
1039362 2024-07-30T19:02:15 Z Ludissey Mecho (IOI09_mecho) C++17
5 / 100
391 ms 12896 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]&&!((dist[x][y]+1)/S>=beeT[x][y]&&grid[x-1][y]!='D')){
            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][y]+1)/S>=beeT[x][y]&&grid[x+1][y]!='D')){
            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)/S>=beeT[x][y]&&grid[x][y-1]!='D')){
            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)/S<beeT[x][y]||grid[x][y+1]=='D')){
            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]!='T'||grid[x-1][y]!='D')&&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]!='T'||grid[x+1][y]!='D')&&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]!='T'||grid[x][y-1]!='D')&&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]!='T'||grid[x][y+1]!='D')&&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 Incorrect 0 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 Incorrect 328 ms 12324 KB Output isn't correct
8 Incorrect 1 ms 344 KB Output isn't correct
9 Incorrect 1 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 1 ms 344 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Incorrect 1 ms 348 KB Output isn't correct
22 Incorrect 1 ms 348 KB Output isn't correct
23 Incorrect 1 ms 352 KB Output isn't correct
24 Incorrect 1 ms 348 KB Output isn't correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Incorrect 1 ms 348 KB Output isn't correct
28 Incorrect 1 ms 348 KB Output isn't correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Incorrect 1 ms 348 KB Output isn't correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Incorrect 1 ms 348 KB Output isn't correct
33 Incorrect 19 ms 2704 KB Output isn't correct
34 Incorrect 21 ms 2752 KB Output isn't correct
35 Incorrect 66 ms 2704 KB Output isn't correct
36 Incorrect 22 ms 3380 KB Output isn't correct
37 Incorrect 27 ms 3424 KB Output isn't correct
38 Incorrect 80 ms 3372 KB Output isn't correct
39 Incorrect 32 ms 4212 KB Output isn't correct
40 Incorrect 34 ms 4212 KB Output isn't correct
41 Incorrect 99 ms 4144 KB Output isn't correct
42 Incorrect 39 ms 5072 KB Output isn't correct
43 Incorrect 41 ms 4976 KB Output isn't correct
44 Incorrect 153 ms 5088 KB Output isn't correct
45 Incorrect 45 ms 6008 KB Output isn't correct
46 Incorrect 47 ms 5992 KB Output isn't correct
47 Incorrect 180 ms 5980 KB Output isn't correct
48 Incorrect 55 ms 7044 KB Output isn't correct
49 Incorrect 59 ms 7344 KB Output isn't correct
50 Incorrect 219 ms 7040 KB Output isn't correct
51 Incorrect 63 ms 8180 KB Output isn't correct
52 Incorrect 72 ms 8180 KB Output isn't correct
53 Incorrect 275 ms 8128 KB Output isn't correct
54 Incorrect 76 ms 9372 KB Output isn't correct
55 Incorrect 87 ms 9344 KB Output isn't correct
56 Incorrect 312 ms 9380 KB Output isn't correct
57 Incorrect 90 ms 10700 KB Output isn't correct
58 Incorrect 100 ms 10672 KB Output isn't correct
59 Incorrect 341 ms 10692 KB Output isn't correct
60 Incorrect 89 ms 12124 KB Output isn't correct
61 Incorrect 108 ms 12060 KB Output isn't correct
62 Incorrect 391 ms 12164 KB Output isn't correct
63 Correct 108 ms 12132 KB Output is correct
64 Incorrect 278 ms 12044 KB Output isn't correct
65 Incorrect 269 ms 12032 KB Output isn't correct
66 Incorrect 101 ms 12176 KB Output isn't correct
67 Incorrect 130 ms 12132 KB Output isn't correct
68 Correct 135 ms 12500 KB Output is correct
69 Incorrect 166 ms 12544 KB Output isn't correct
70 Incorrect 131 ms 12524 KB Output isn't correct
71 Incorrect 132 ms 12508 KB Output isn't correct
72 Incorrect 140 ms 12516 KB Output isn't correct
73 Correct 149 ms 12852 KB Output is correct
74 Incorrect 219 ms 12828 KB Output isn't correct
75 Incorrect 232 ms 12896 KB Output isn't correct
76 Incorrect 226 ms 12852 KB Output isn't correct
77 Incorrect 223 ms 12844 KB Output isn't correct
78 Incorrect 269 ms 12744 KB Output isn't correct
79 Incorrect 208 ms 12860 KB Output isn't correct
80 Incorrect 238 ms 12784 KB Output isn't correct
81 Incorrect 265 ms 12768 KB Output isn't correct
82 Incorrect 219 ms 12764 KB Output isn't correct
83 Incorrect 275 ms 12684 KB Output isn't correct
84 Incorrect 271 ms 12664 KB Output isn't correct
85 Incorrect 245 ms 12736 KB Output isn't correct
86 Incorrect 294 ms 12808 KB Output isn't correct
87 Incorrect 258 ms 12644 KB Output isn't correct
88 Incorrect 278 ms 12556 KB Output isn't correct
89 Incorrect 284 ms 12576 KB Output isn't correct
90 Incorrect 300 ms 12504 KB Output isn't correct
91 Incorrect 287 ms 12612 KB Output isn't correct
92 Incorrect 271 ms 12552 KB Output isn't correct