Submission #862428

# Submission time Handle Problem Language Result Execution time Memory
862428 2023-10-18T08:17:02 Z dosts Mecho (IOI09_mecho) C++14
54 / 100
160 ms 11392 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>


void solve() {
	int n,k;
	cin >> n >> k;
	char grid[n+1][n+1];
	queue<pii> q;
	vector<vi> bee(n+1,vi(n+1,-1));
	int sx,sy,hx,hy;
	F(i,n) {
		string s;
		cin >> s;
		F(j,n) {
			grid[i][j]  = s[j-1];
			if (s[j-1] == 'H') {
				q.push({i,j});
				bee[i][j] = 0;
			}
			if (s[j-1] == 'D') {
				hx = i;
				hy = j;
			}
			if (s[j-1] == 'M') {
				sx = i;
				sy = j;
			}
		}
	}
	vi dx = {1,0,-1,0};
	vi dy = {0,1,0,-1};
	while (!q.empty()) {
		pii f = q.front();
		q.pop();
		int x = f.first;
		int y = f.second;
		for (int i=0;i<4;i++) { 
			int gx = x+dx[i];
			int gy = y+dy[i];
			if (gx < 1 || gx > n) continue;
			if (gy < 1 || gy > n) continue;
			if (grid[gx][gy] == 'T') continue;
			if (grid[gx][gy] == 'D') continue;
			if (bee[gx][gy] != -1) continue;
			bee[gx][gy] = bee[x][y]+1;
			q.push({gx,gy});
		}
	}
	int l = 0;
	int r = 1e9;
	while (l<=r) {
		int w = (l+r) >> 1;
		if (w >= bee[sx][sy]) {
			r = w-1;
			continue;
		}
		vector<vi> dist(n+1,vi(n+1,-1));
		dist[sx][sy] = 0;
		q.push({sx,sy});
		while (!q.empty()) {
			pii f = q.front();
			q.pop();
			int x = f.first;
			int y = f.second;
			for (int i=0;i<4;i++) { 
				int gx = x+dx[i];
				int gy = y+dy[i];
				if (gx < 1 || gx > n) continue;
				if (gy < 1 || gy > n) continue;
				if (grid[gx][gy] == 'T') continue;
				if (dist[gx][gy] != -1) continue;
				if (bee[gx][gy] != -1 && bee[gx][gy] < w+(dist[x][y]/k)+1) continue;
				dist[gx][gy] = dist[x][y]+1;
				q.push({gx,gy});
			}
		}
		if (dist[hx][hy]!=-1) l = w+1;
		else r = w-1;
	}
	cout << r << endl;
}       
                 
                 
                             
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}

Compilation message

mecho.cpp: In function 'void solve()':
mecho.cpp:63:22: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |   if (w >= bee[sx][sy]) {
      |                      ^
mecho.cpp:63:18: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |   if (w >= bee[sx][sy]) {
      |                  ^
mecho.cpp:87:14: warning: 'hx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |   if (dist[hx][hy]!=-1) l = w+1;
      |              ^
mecho.cpp:87:18: warning: 'hy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |   if (dist[hx][hy]!=-1) l = w+1;
      |                  ^
# 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 Correct 0 ms 348 KB Output is correct
7 Correct 91 ms 11244 KB Output is correct
8 Incorrect 0 ms 344 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 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 0 ms 344 KB Output isn't correct
24 Correct 0 ms 348 KB Output is correct
25 Incorrect 0 ms 348 KB Output isn't correct
26 Correct 0 ms 348 KB Output is correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Correct 0 ms 348 KB Output is correct
29 Incorrect 0 ms 348 KB Output isn't correct
30 Correct 0 ms 348 KB Output is correct
31 Incorrect 0 ms 348 KB Output isn't correct
32 Correct 1 ms 344 KB Output is correct
33 Incorrect 7 ms 2540 KB Output isn't correct
34 Correct 7 ms 2528 KB Output is correct
35 Correct 17 ms 2504 KB Output is correct
36 Incorrect 6 ms 3092 KB Output isn't correct
37 Correct 6 ms 3152 KB Output is correct
38 Correct 26 ms 3168 KB Output is correct
39 Incorrect 8 ms 3868 KB Output isn't correct
40 Correct 8 ms 3844 KB Output is correct
41 Correct 30 ms 3912 KB Output is correct
42 Incorrect 8 ms 4636 KB Output isn't correct
43 Correct 7 ms 4636 KB Output is correct
44 Correct 41 ms 4640 KB Output is correct
45 Incorrect 14 ms 5572 KB Output isn't correct
46 Correct 11 ms 5548 KB Output is correct
47 Correct 55 ms 5584 KB Output is correct
48 Incorrect 16 ms 6560 KB Output isn't correct
49 Correct 17 ms 6544 KB Output is correct
50 Correct 60 ms 6528 KB Output is correct
51 Incorrect 19 ms 7604 KB Output isn't correct
52 Correct 20 ms 7588 KB Output is correct
53 Correct 87 ms 7856 KB Output is correct
54 Incorrect 25 ms 8792 KB Output isn't correct
55 Correct 27 ms 8716 KB Output is correct
56 Correct 86 ms 8692 KB Output is correct
57 Incorrect 22 ms 9968 KB Output isn't correct
58 Correct 16 ms 9908 KB Output is correct
59 Correct 91 ms 9904 KB Output is correct
60 Incorrect 25 ms 11244 KB Output isn't correct
61 Correct 28 ms 11256 KB Output is correct
62 Correct 116 ms 11212 KB Output is correct
63 Correct 107 ms 11204 KB Output is correct
64 Correct 160 ms 11212 KB Output is correct
65 Correct 152 ms 11188 KB Output is correct
66 Incorrect 117 ms 11212 KB Output isn't correct
67 Correct 95 ms 11212 KB Output is correct
68 Correct 48 ms 11220 KB Output is correct
69 Correct 47 ms 11232 KB Output is correct
70 Correct 35 ms 11228 KB Output is correct
71 Correct 40 ms 11260 KB Output is correct
72 Correct 30 ms 11260 KB Output is correct
73 Correct 40 ms 11252 KB Output is correct
74 Correct 58 ms 11260 KB Output is correct
75 Correct 63 ms 11292 KB Output is correct
76 Correct 56 ms 11268 KB Output is correct
77 Correct 59 ms 11188 KB Output is correct
78 Correct 66 ms 11136 KB Output is correct
79 Correct 57 ms 11324 KB Output is correct
80 Correct 59 ms 11288 KB Output is correct
81 Correct 67 ms 11392 KB Output is correct
82 Correct 56 ms 11184 KB Output is correct
83 Correct 73 ms 11232 KB Output is correct
84 Correct 77 ms 11232 KB Output is correct
85 Correct 70 ms 11252 KB Output is correct
86 Correct 70 ms 11248 KB Output is correct
87 Correct 71 ms 11140 KB Output is correct
88 Correct 78 ms 11248 KB Output is correct
89 Correct 82 ms 11352 KB Output is correct
90 Correct 79 ms 11248 KB Output is correct
91 Correct 74 ms 11244 KB Output is correct
92 Correct 76 ms 11208 KB Output is correct