Submission #882835

# Submission time Handle Problem Language Result Execution time Memory
882835 2023-12-03T20:03:36 Z abhinavshukla408 Mecho (IOI09_mecho) C++17
3 / 100
356 ms 31332 KB
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <math.h>
 
using namespace std;
 
#define endl "\n"
#define int int64_t 
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FOR0(i,a) FOR(i,0,a)
#define FOR1(i,a) for (int i = (1); i <= (a); ++i)
#define TRAV(a,x) for (auto& a: x)

using pii = pair<int,int>;
using vi = vector<int>;
vi dx = {-1,0,1,0};
vi dy = {0,-1,0,1};
const int NMAX=801;
int N;
int S;
pii start={0,0};
pii end2={0,0};

bool f(int k,string grid[NMAX][NMAX],int distBees[NMAX][NMAX]){
	queue<pii> cur;
	cur.push(start);
	int dist[N][N];
	FOR0(i,N){
		FOR0(j,N){
			dist[i][j]=-1;
		}
	}
	dist[start.first][start.second]=0;
	while(!cur.empty()){
		pii curNode=cur.front();
		cur.pop();
		FOR0(i,4){
			int newR=curNode.first+dx[i];
			int newC=curNode.second+dy[i];
			if(newR<0 || newR>=N || newC<0 || newC>=N){continue;}
			if((grid[newR][newC]=="G" || grid[newR][newC]=="D") && dist[newR][newC]==(-1)){
				if((distBees[newR][newC]-k)>((dist[curNode.first][curNode.second]+1)/S)){
					//cout<<newR<<" "<<newC<<endl;
					dist[newR][newC]=dist[curNode.first][curNode.second]+1;
					cur.push({newR,newC});
				}
			}
		}
	}

	if(dist[end2.first][end2.second]!=(-1)){
		return true;
	}
	return false;

}

int last_true(int lo, int hi,string grid[NMAX][NMAX],int distBees[NMAX][NMAX]) {
	// if none of the values in the range work, return lo - 1
	lo--;
	while (lo < hi) {
		// find the middle of the current range (rounding up)
		int mid = lo + (hi - lo + 1) / 2;
		if (f(mid,grid,distBees)) {
			// if mid works, then all numbers smaller than mid also work
			lo = mid;
		} else {
			// if mid does not work, greater values would not work either
			hi = mid - 1;
		}
	}
	return lo;
}


int32_t main(){

	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	// cout<<"yo"<<endl;
	// return 0;
	cin>>N>>S;
	string grid[NMAX][NMAX];
	int distBees[NMAX][NMAX];
	
	queue<pii> cur;
	FOR0(r,N){
		string in;
		cin>>in;
		FOR0(c,N){
			distBees[r][c]=-1;
			grid[r][c]=(in.at(c));
			if(grid[r][c]=="H"){
				cur.push({r,c});
				distBees[r][c]=0;
			}
			if(grid[r][c]=="M"){
				start={r,c};
			}
			if(grid[r][c]=="D"){
				end2={r,c};
			}
		}
	}
	// return 0;
	while(!cur.empty()){
		pii curNode=cur.front();
		int curR=curNode.first;
		int curC=curNode.second;
		cur.pop();
		FOR0(i,4){
				int newR=curNode.first+dx[i];
				int newC=curNode.second+dy[i];
				if(newR<0 || newR>=N || newC<0 || newC>=N){continue;}
				if(grid[newR][newC]!="M" && distBees[newR][newC]==(-1)){
					distBees[newR][newC]=distBees[curR][curC]+1;
					cur.push({newR,newC});
				}
		}
	}
	//return 0;
	int ans=last_true(0,100000000,grid,distBees);
	if(ans==100000000){
		ans=0;
	}
	cout<<ans-1<<endl;
	



	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 25436 KB Output isn't correct
2 Incorrect 15 ms 25436 KB Output isn't correct
3 Incorrect 14 ms 25436 KB Output isn't correct
4 Incorrect 16 ms 25432 KB Output isn't correct
5 Incorrect 15 ms 25560 KB Output isn't correct
6 Incorrect 17 ms 25436 KB Output isn't correct
7 Incorrect 199 ms 30804 KB Output isn't correct
8 Incorrect 15 ms 25432 KB Output isn't correct
9 Incorrect 15 ms 25432 KB Output isn't correct
10 Incorrect 15 ms 25436 KB Output isn't correct
11 Incorrect 15 ms 25436 KB Output isn't correct
12 Incorrect 15 ms 25564 KB Output isn't correct
13 Correct 15 ms 25432 KB Output is correct
14 Incorrect 15 ms 25432 KB Output isn't correct
15 Incorrect 14 ms 25336 KB Output isn't correct
16 Incorrect 15 ms 25432 KB Output isn't correct
17 Incorrect 16 ms 25688 KB Output isn't correct
18 Incorrect 20 ms 25436 KB Output isn't correct
19 Incorrect 15 ms 25436 KB Output isn't correct
20 Incorrect 15 ms 25436 KB Output isn't correct
21 Incorrect 16 ms 25432 KB Output isn't correct
22 Incorrect 15 ms 25432 KB Output isn't correct
23 Incorrect 15 ms 25560 KB Output isn't correct
24 Incorrect 15 ms 25436 KB Output isn't correct
25 Incorrect 15 ms 25436 KB Output isn't correct
26 Incorrect 15 ms 25436 KB Output isn't correct
27 Incorrect 15 ms 25600 KB Output isn't correct
28 Incorrect 18 ms 25512 KB Output isn't correct
29 Incorrect 19 ms 25548 KB Output isn't correct
30 Incorrect 16 ms 25560 KB Output isn't correct
31 Incorrect 15 ms 25436 KB Output isn't correct
32 Incorrect 15 ms 25436 KB Output isn't correct
33 Incorrect 25 ms 26460 KB Output isn't correct
34 Incorrect 26 ms 26456 KB Output isn't correct
35 Incorrect 56 ms 26452 KB Output isn't correct
36 Incorrect 34 ms 26716 KB Output isn't correct
37 Incorrect 30 ms 26652 KB Output isn't correct
38 Incorrect 71 ms 26716 KB Output isn't correct
39 Incorrect 35 ms 26972 KB Output isn't correct
40 Incorrect 32 ms 26972 KB Output isn't correct
41 Incorrect 84 ms 26964 KB Output isn't correct
42 Incorrect 35 ms 27472 KB Output isn't correct
43 Incorrect 38 ms 27480 KB Output isn't correct
44 Incorrect 104 ms 27380 KB Output isn't correct
45 Incorrect 47 ms 27728 KB Output isn't correct
46 Incorrect 55 ms 27864 KB Output isn't correct
47 Incorrect 131 ms 27940 KB Output isn't correct
48 Incorrect 44 ms 28136 KB Output isn't correct
49 Incorrect 56 ms 28392 KB Output isn't correct
50 Incorrect 173 ms 28396 KB Output isn't correct
51 Incorrect 55 ms 28756 KB Output isn't correct
52 Incorrect 61 ms 28756 KB Output isn't correct
53 Incorrect 193 ms 28892 KB Output isn't correct
54 Incorrect 52 ms 29264 KB Output isn't correct
55 Incorrect 85 ms 29172 KB Output isn't correct
56 Incorrect 229 ms 29264 KB Output isn't correct
57 Incorrect 85 ms 29776 KB Output isn't correct
58 Incorrect 89 ms 29932 KB Output isn't correct
59 Incorrect 266 ms 29780 KB Output isn't correct
60 Incorrect 63 ms 30444 KB Output isn't correct
61 Incorrect 90 ms 30548 KB Output isn't correct
62 Incorrect 356 ms 30452 KB Output isn't correct
63 Incorrect 82 ms 30448 KB Output isn't correct
64 Incorrect 284 ms 30440 KB Output isn't correct
65 Incorrect 253 ms 30484 KB Output isn't correct
66 Incorrect 84 ms 30548 KB Output isn't correct
67 Incorrect 112 ms 30548 KB Output isn't correct
68 Incorrect 87 ms 30692 KB Output isn't correct
69 Incorrect 91 ms 30900 KB Output isn't correct
70 Incorrect 85 ms 30752 KB Output isn't correct
71 Incorrect 114 ms 30752 KB Output isn't correct
72 Incorrect 81 ms 30676 KB Output isn't correct
73 Correct 101 ms 31056 KB Output is correct
74 Incorrect 143 ms 31056 KB Output isn't correct
75 Incorrect 145 ms 31240 KB Output isn't correct
76 Incorrect 140 ms 31140 KB Output isn't correct
77 Incorrect 154 ms 31140 KB Output isn't correct
78 Incorrect 202 ms 31060 KB Output isn't correct
79 Incorrect 142 ms 31056 KB Output isn't correct
80 Incorrect 149 ms 31056 KB Output isn't correct
81 Incorrect 190 ms 31332 KB Output isn't correct
82 Incorrect 145 ms 30932 KB Output isn't correct
83 Incorrect 171 ms 31000 KB Output isn't correct
84 Incorrect 158 ms 30936 KB Output isn't correct
85 Incorrect 179 ms 30804 KB Output isn't correct
86 Incorrect 187 ms 30756 KB Output isn't correct
87 Incorrect 176 ms 30804 KB Output isn't correct
88 Incorrect 172 ms 30764 KB Output isn't correct
89 Incorrect 189 ms 30908 KB Output isn't correct
90 Incorrect 204 ms 30908 KB Output isn't correct
91 Incorrect 196 ms 30764 KB Output isn't correct
92 Incorrect 213 ms 30760 KB Output isn't correct