Submission #742730

# Submission time Handle Problem Language Result Execution time Memory
742730 2023-05-16T20:01:53 Z CSQ31 Mecho (IOI09_mecho) C++17
38 / 100
464 ms 11536 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int n,s,dx[4] = {0,0,1,-1},dy[4] = {1,-1,0,0};
int dist[1000][1000],bdist[1000][1000],blk[1000][1000];
char grid[1000][1000];
pii st,ed;
bool check(int tim){
	queue<pii>bee;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			dist[i][j] = bdist[i][j] = 1e9;
			blk[i][j] = 1;
			if(grid[i][j] == 'H'){
				bee.push({i,j});
				bdist[i][j] = 0;
			}
			if(grid[i][j] != 'H' && grid[i][j] != 'T')blk[i][j] = 0;
		}
	}
	while(!bee.empty()){
		auto v = bee.front();
		if(bdist[v.fi][v.se] == tim+1)break;
		bee.pop();
		blk[v.fi][v.se] = 1;
		for(int i=0;i<4;i++){
			int x = v.fi+dx[i];
			int y = v.se+dy[i];
			if(x>=0 && y>=0 && x<n && y<n && bdist[x][y] == 1e9 && grid[x][y] == 'G'){
				bee.push({x,y});
				bdist[x][y] = bdist[v.fi][v.se]+1;
			}
		}
	}
	
	queue<pii>q;
	q.push(st);
	dist[st.fi][st.se] = 0;
	int cnt = 1;
	while(!q.empty()){
		pii v = q.front();
		q.pop();
		if((dist[v.fi][v.se]+s-1)/s > cnt){ //move the bees
			cnt++;
			tim++;
			while(!bee.empty()){
				auto v = bee.front();
				if(bdist[v.fi][v.se] == tim+1)break;
				bee.pop();
				blk[v.fi][v.se] = 1;
				for(int i=0;i<4;i++){
					int x = v.fi+dx[i];
					int y = v.se+dy[i];
					if(x>=0 && y>=0 && x<n && y<n && bdist[x][y] == 1e9 && grid[x][y] == 'G'){
						bee.push({x,y});
						bdist[x][y] = bdist[v.fi][v.se]+1;
					}
				}
			}
		}
		if(blk[v.fi][v.se])continue;
		for(int i=0;i<4;i++){
            int x = v.fi+dx[i];
			int y = v.se+dy[i];
			if(x>=0 && y>=0 && x<n && y<n && !blk[x][y] && dist[x][y] == 1e9){
				q.push({x,y});
				dist[x][y] = dist[v.fi][v.se]+1;
			}
		}
	}
	
	return dist[ed.fi][ed.se] != 1e9;
}
int main()
{
	owo
	cin>>n>>s;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>grid[i][j];	
			if(grid[i][j] == 'M')st = {i,j};
			if(grid[i][j] == 'D')ed = {i,j};
		}
	}
	if(!check(0)){
		cout<<-1;
		return 0;
	}
	int l = 0,r = n*n;
	while(r>=l){
		int mid = (l+r)/2;
		if(check(mid))l = mid+1;
		else r = mid-1;
	}
	cout<<r<<'\n';
	
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 322 ms 11224 KB Output is correct
8 Incorrect 1 ms 468 KB Output isn't correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Incorrect 2 ms 980 KB Output isn't correct
13 Incorrect 1 ms 980 KB Output isn't correct
14 Correct 1 ms 980 KB Output is correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Correct 1 ms 596 KB Output is correct
17 Incorrect 1 ms 596 KB Output isn't correct
18 Correct 1 ms 596 KB Output is correct
19 Incorrect 1 ms 596 KB Output isn't correct
20 Correct 1 ms 596 KB Output is correct
21 Incorrect 1 ms 724 KB Output isn't correct
22 Correct 1 ms 724 KB Output is correct
23 Incorrect 1 ms 968 KB Output isn't correct
24 Correct 2 ms 852 KB Output is correct
25 Incorrect 1 ms 1096 KB Output isn't correct
26 Correct 2 ms 980 KB Output is correct
27 Incorrect 1 ms 1108 KB Output isn't correct
28 Correct 2 ms 1096 KB Output is correct
29 Incorrect 2 ms 1236 KB Output isn't correct
30 Correct 2 ms 1236 KB Output is correct
31 Incorrect 2 ms 1236 KB Output isn't correct
32 Correct 2 ms 1236 KB Output is correct
33 Incorrect 30 ms 4872 KB Output isn't correct
34 Correct 31 ms 4792 KB Output is correct
35 Correct 39 ms 4888 KB Output is correct
36 Incorrect 39 ms 5588 KB Output isn't correct
37 Correct 37 ms 5588 KB Output is correct
38 Correct 48 ms 5500 KB Output is correct
39 Incorrect 53 ms 6228 KB Output isn't correct
40 Correct 47 ms 6216 KB Output is correct
41 Correct 66 ms 6252 KB Output is correct
42 Incorrect 57 ms 6928 KB Output isn't correct
43 Correct 57 ms 6932 KB Output is correct
44 Correct 86 ms 6868 KB Output is correct
45 Incorrect 76 ms 7616 KB Output isn't correct
46 Correct 72 ms 7636 KB Output is correct
47 Correct 99 ms 7636 KB Output is correct
48 Incorrect 87 ms 8324 KB Output isn't correct
49 Correct 86 ms 8276 KB Output is correct
50 Correct 112 ms 8316 KB Output is correct
51 Incorrect 109 ms 8924 KB Output isn't correct
52 Correct 103 ms 9076 KB Output is correct
53 Correct 140 ms 9024 KB Output is correct
54 Incorrect 117 ms 9712 KB Output isn't correct
55 Correct 115 ms 9684 KB Output is correct
56 Correct 169 ms 9716 KB Output is correct
57 Incorrect 132 ms 10412 KB Output isn't correct
58 Correct 136 ms 10324 KB Output is correct
59 Correct 201 ms 10440 KB Output is correct
60 Incorrect 162 ms 11132 KB Output isn't correct
61 Correct 153 ms 11064 KB Output is correct
62 Correct 244 ms 11132 KB Output is correct
63 Correct 367 ms 11080 KB Output is correct
64 Correct 373 ms 11132 KB Output is correct
65 Correct 341 ms 11152 KB Output is correct
66 Incorrect 406 ms 11128 KB Output isn't correct
67 Correct 29 ms 11084 KB Output is correct
68 Correct 386 ms 11152 KB Output is correct
69 Correct 340 ms 11212 KB Output is correct
70 Correct 369 ms 11156 KB Output is correct
71 Correct 401 ms 11092 KB Output is correct
72 Incorrect 437 ms 11116 KB Output isn't correct
73 Incorrect 416 ms 11408 KB Output isn't correct
74 Correct 368 ms 11408 KB Output is correct
75 Correct 464 ms 11536 KB Output is correct
76 Correct 399 ms 11408 KB Output is correct
77 Correct 403 ms 11536 KB Output is correct
78 Correct 30 ms 11336 KB Output is correct
79 Correct 351 ms 11316 KB Output is correct
80 Correct 341 ms 11512 KB Output is correct
81 Correct 325 ms 11388 KB Output is correct
82 Correct 337 ms 11448 KB Output is correct
83 Correct 328 ms 11392 KB Output is correct
84 Correct 334 ms 11340 KB Output is correct
85 Correct 348 ms 11336 KB Output is correct
86 Correct 341 ms 11348 KB Output is correct
87 Correct 330 ms 11352 KB Output is correct
88 Correct 330 ms 11292 KB Output is correct
89 Correct 319 ms 11168 KB Output is correct
90 Correct 325 ms 11300 KB Output is correct
91 Correct 345 ms 11300 KB Output is correct
92 Correct 337 ms 11324 KB Output is correct