Submission #1013295

# Submission time Handle Problem Language Result Execution time Memory
1013295 2024-07-03T11:40:33 Z ducksaysquack Mecho (IOI09_mecho) C++
84 / 100
163 ms 12316 KB
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int n, m;
int C[]{0,1,0,-1}, R[]{1,0,-1,0};
pair<int,int> a, b; queue<pair<int,int>> q;
vector<vector<int>> g(805, vector<int>(805, 1e9));
vector<string> v(805);
bool bfs(int k) {
	vector<vector<int>> dis(n, vector<int>(n, 1e9));
	q.push(a); dis[a.f][a.s] = 0;
    while(!q.empty()) {
    	pair<int,int> r = q.front(); q.pop();
    	for(int i=0;i<4;i++) {
    		int x = r.f+R[i], y = r.s+C[i];
    		if(0 <= x && x < n && 0 <= y && y < n && ((dis[r.f][r.s]+1)/m < g[x][y]-k || (dis[r.f][r.s]+1)/m <= g[x][y]-k && v[x][y] == 'D'))
    			if(dis[r.f][r.s]+1 < dis[x][y] && (v[x][y] == 'G' || v[x][y] == 'D')) {
    				dis[x][y] = dis[r.f][r.s]+1;
    				q.push({x,y});
    			}
    	}
    }
    if(dis[b.f][b.s] == 1e9) return false;
    return true;
}
signed main() {
    //ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m; for(int i=0;i<n;i++) cin >> v[i];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) {
    	if(v[i][j] == 'M') a.f = i, a.s = j;
    	if(v[i][j] == 'D') b.f = i, b.s = j;
    	if(v[i][j] == 'H') {q.push({i,j}); g[i][j] = 0;}
    }
    while(!q.empty()) {
    	pair<int,int> r = q.front(); q.pop();
    	for(int i=0;i<4;i++) {
    		int x = r.f+R[i], y = r.s+C[i];
    		if(0 <= x && x < n && 0 <= y && y < n) if(g[r.f][r.s]+1 < g[x][y] && v[x][y] == 'G') {
    			g[x][y] = g[r.f][r.s]+1;
    			q.push({x,y});
    		}
    	}
    }
    int l = -1, r = 1e6;
    while(l<r) {
    	int d = (l+r+1)/2;
    	if(bfs(d)) l = d;
    	else r = d-1;
    }
    cout << l;
}

Compilation message

mecho.cpp: In function 'bool bfs(long long int)':
mecho.cpp:18:117: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   18 |       if(0 <= x && x < n && 0 <= y && y < n && ((dis[r.f][r.s]+1)/m < g[x][y]-k || (dis[r.f][r.s]+1)/m <= g[x][y]-k && v[x][y] == 'D'))
      |                                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5468 KB Output is correct
2 Correct 3 ms 5468 KB Output is correct
3 Correct 2 ms 5720 KB Output is correct
4 Correct 3 ms 5468 KB Output is correct
5 Correct 3 ms 5468 KB Output is correct
6 Correct 3 ms 5536 KB Output is correct
7 Correct 92 ms 12112 KB Output is correct
8 Correct 3 ms 5464 KB Output is correct
9 Correct 4 ms 5468 KB Output is correct
10 Correct 3 ms 5484 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Incorrect 3 ms 5468 KB Output isn't correct
13 Incorrect 3 ms 5464 KB Output isn't correct
14 Correct 3 ms 5468 KB Output is correct
15 Correct 3 ms 5468 KB Output is correct
16 Correct 2 ms 5468 KB Output is correct
17 Correct 3 ms 5468 KB Output is correct
18 Correct 3 ms 5720 KB Output is correct
19 Correct 2 ms 5468 KB Output is correct
20 Correct 3 ms 5428 KB Output is correct
21 Correct 2 ms 5468 KB Output is correct
22 Correct 3 ms 5468 KB Output is correct
23 Correct 3 ms 5468 KB Output is correct
24 Correct 3 ms 5548 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 3 ms 5560 KB Output is correct
28 Correct 3 ms 5468 KB Output is correct
29 Correct 3 ms 5568 KB Output is correct
30 Correct 3 ms 5720 KB Output is correct
31 Correct 3 ms 5468 KB Output is correct
32 Correct 2 ms 5468 KB Output is correct
33 Correct 15 ms 6864 KB Output is correct
34 Correct 11 ms 6808 KB Output is correct
35 Correct 23 ms 6860 KB Output is correct
36 Correct 13 ms 7220 KB Output is correct
37 Correct 13 ms 7172 KB Output is correct
38 Correct 32 ms 7216 KB Output is correct
39 Correct 17 ms 7624 KB Output is correct
40 Correct 16 ms 7628 KB Output is correct
41 Correct 34 ms 7640 KB Output is correct
42 Correct 18 ms 8288 KB Output is correct
43 Correct 17 ms 8320 KB Output is correct
44 Correct 55 ms 8292 KB Output is correct
45 Correct 21 ms 8820 KB Output is correct
46 Correct 22 ms 8796 KB Output is correct
47 Correct 53 ms 8804 KB Output is correct
48 Correct 27 ms 9388 KB Output is correct
49 Correct 25 ms 9376 KB Output is correct
50 Correct 66 ms 9368 KB Output is correct
51 Correct 28 ms 9936 KB Output is correct
52 Correct 33 ms 10012 KB Output is correct
53 Correct 83 ms 9940 KB Output is correct
54 Correct 35 ms 10652 KB Output is correct
55 Correct 34 ms 10664 KB Output is correct
56 Correct 93 ms 10644 KB Output is correct
57 Correct 36 ms 11360 KB Output is correct
58 Correct 36 ms 11368 KB Output is correct
59 Correct 108 ms 11304 KB Output is correct
60 Correct 41 ms 12112 KB Output is correct
61 Correct 42 ms 12052 KB Output is correct
62 Correct 132 ms 12164 KB Output is correct
63 Correct 119 ms 12032 KB Output is correct
64 Correct 163 ms 12032 KB Output is correct
65 Correct 141 ms 12116 KB Output is correct
66 Correct 130 ms 12096 KB Output is correct
67 Correct 118 ms 12020 KB Output is correct
68 Correct 72 ms 12156 KB Output is correct
69 Correct 71 ms 12148 KB Output is correct
70 Correct 64 ms 12160 KB Output is correct
71 Correct 61 ms 12136 KB Output is correct
72 Incorrect 53 ms 12092 KB Output isn't correct
73 Incorrect 74 ms 12104 KB Output isn't correct
74 Correct 66 ms 12072 KB Output is correct
75 Correct 79 ms 12084 KB Output is correct
76 Correct 69 ms 12112 KB Output is correct
77 Correct 94 ms 12124 KB Output is correct
78 Correct 97 ms 12112 KB Output is correct
79 Correct 68 ms 12108 KB Output is correct
80 Correct 83 ms 12100 KB Output is correct
81 Correct 87 ms 12088 KB Output is correct
82 Correct 75 ms 12096 KB Output is correct
83 Correct 81 ms 12080 KB Output is correct
84 Correct 87 ms 12084 KB Output is correct
85 Correct 84 ms 12316 KB Output is correct
86 Correct 99 ms 12076 KB Output is correct
87 Correct 87 ms 12280 KB Output is correct
88 Correct 99 ms 12116 KB Output is correct
89 Correct 93 ms 12068 KB Output is correct
90 Correct 95 ms 12092 KB Output is correct
91 Correct 94 ms 12112 KB Output is correct
92 Correct 90 ms 12044 KB Output is correct