Submission #341021

# Submission time Handle Problem Language Result Execution time Memory
341021 2020-12-28T22:20:51 Z peuch Mecho (IOI09_mecho) C++17
13 / 100
1000 ms 17388 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1010;

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int n;
long long s;
int hx, hy;
int mx, my;
char grid[MAXN][MAXN];
long long beeDist[MAXN][MAXN];
int marc[MAXN][MAXN];
long long dist[MAXN][MAXN];

void preCalc();
bool test(long long temp);
long long bb();

int main(){
	scanf("%d %lld", &n, &s);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			scanf(" %c", &grid[i][j]);
			if(grid[i][j] == 'D') hx = i, hy = j;
			if(grid[i][j] == 'M') mx = i, my = j;
		}
	}
	preCalc();
	printf("%lld\n", bb());
}

void preCalc(){
	queue<int> fila;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(grid[i][j] != 'H') beeDist[i][j] = 2e18;
			else{
				marc[i][j] = 1;
				fila.push(i);
				fila.push(j);
			}
		}
	}
	while(!fila.empty()){
		int curx = fila.front();
		fila.pop();
		int cury = fila.front();
		fila.pop();
		for(int i = 0; i < 4; i++){
			int vizx = curx + dx[i];
			int vizy = cury + dy[i];
			if(vizx <= 0 || vizx > n) continue;
			if(vizy <= 0 || vizy > n) continue;
			if(grid[vizx][vizy] == 'T') continue;
			if(grid[vizx][vizy] == 'D') continue;
			if(marc[vizx][vizy]) continue;
			marc[vizx][vizy] = 1;
			beeDist[vizx][vizy] = beeDist[curx][cury] + 1;
			fila.push(vizx);
			fila.push(vizy);
		}
	}
}

bool test(long long temp){
	queue<int> fila;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			marc[i][j] = 0;
			dist[i][j] = 0;
		}
	}
	fila.push(mx);
	fila.push(my);
	marc[mx][my] = 1;
	dist[mx][my] = temp * s;
	while(!fila.empty()){
		int curx = fila.front();
		fila.pop();
		int cury = fila.front();
		fila.pop();
		for(int i = 0; i < 4; i++){
			int vizx = curx + dx[i];
			int vizy = cury + dy[i];
			if(vizx <= 0 || vizx > n) continue;
			if(vizy <= 0 || vizy > n) continue;
			if(grid[vizx][vizy] == 'T') continue;
			if((dist[curx][cury] + s) / s > beeDist[vizx][vizy]) continue;
			if(marc[vizx][vizy]) continue;
			marc[vizx][vizy] = 1;
			dist[vizx][vizy] = dist[curx][cury] + 1;
			fila.push(vizx);
			fila.push(vizy);
		}
	}
	return marc[hx][hy];
}

long long bb(){
	long long ini = 0, fim = 1e18 + 10;
	if(!test(ini)) return -1;
	while(ini != fim){
		long long mid = (ini + fim) >> 1;
		if(ini == fim - 1) mid = fim;
		if(test(mid)) ini = mid;
		else fim = mid - 1;
	}
	return ini;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf("%d %lld", &n, &s);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
mecho.cpp:26:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |    scanf(" %c", &grid[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Execution timed out 1092 ms 17004 KB Time limit exceeded
8 Incorrect 1 ms 492 KB Output isn't correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Incorrect 2 ms 1132 KB Output isn't correct
13 Incorrect 1 ms 1004 KB Output isn't correct
14 Correct 1 ms 1132 KB Output is correct
15 Incorrect 1 ms 620 KB Output isn't correct
16 Correct 1 ms 620 KB Output is correct
17 Incorrect 1 ms 620 KB Output isn't correct
18 Correct 1 ms 620 KB Output is correct
19 Incorrect 1 ms 748 KB Output isn't correct
20 Correct 1 ms 748 KB Output is correct
21 Incorrect 1 ms 876 KB Output isn't correct
22 Incorrect 2 ms 876 KB Output isn't correct
23 Incorrect 1 ms 1004 KB Output isn't correct
24 Incorrect 3 ms 1004 KB Output isn't correct
25 Incorrect 2 ms 1132 KB Output isn't correct
26 Incorrect 3 ms 1132 KB Output isn't correct
27 Incorrect 2 ms 1260 KB Output isn't correct
28 Incorrect 3 ms 1260 KB Output isn't correct
29 Incorrect 2 ms 1260 KB Output isn't correct
30 Incorrect 3 ms 1260 KB Output isn't correct
31 Incorrect 2 ms 1388 KB Output isn't correct
32 Incorrect 4 ms 1388 KB Output isn't correct
33 Incorrect 21 ms 6764 KB Output isn't correct
34 Incorrect 71 ms 6764 KB Output isn't correct
35 Incorrect 133 ms 6892 KB Output isn't correct
36 Incorrect 28 ms 8172 KB Output isn't correct
37 Incorrect 77 ms 8044 KB Output isn't correct
38 Incorrect 178 ms 8044 KB Output isn't correct
39 Incorrect 34 ms 9324 KB Output isn't correct
40 Incorrect 99 ms 9324 KB Output isn't correct
41 Incorrect 276 ms 9324 KB Output isn't correct
42 Incorrect 42 ms 10772 KB Output isn't correct
43 Incorrect 109 ms 10732 KB Output isn't correct
44 Incorrect 376 ms 10752 KB Output isn't correct
45 Incorrect 52 ms 11756 KB Output isn't correct
46 Incorrect 175 ms 11756 KB Output isn't correct
47 Incorrect 460 ms 11756 KB Output isn't correct
48 Incorrect 63 ms 12780 KB Output isn't correct
49 Incorrect 181 ms 12780 KB Output isn't correct
50 Incorrect 473 ms 12864 KB Output isn't correct
51 Incorrect 78 ms 13804 KB Output isn't correct
52 Incorrect 207 ms 13804 KB Output isn't correct
53 Incorrect 631 ms 14060 KB Output isn't correct
54 Incorrect 102 ms 14828 KB Output isn't correct
55 Incorrect 240 ms 14828 KB Output isn't correct
56 Incorrect 772 ms 14956 KB Output isn't correct
57 Incorrect 111 ms 15852 KB Output isn't correct
58 Incorrect 280 ms 15852 KB Output isn't correct
59 Incorrect 836 ms 15980 KB Output isn't correct
60 Incorrect 125 ms 17004 KB Output isn't correct
61 Incorrect 339 ms 17000 KB Output isn't correct
62 Incorrect 951 ms 17260 KB Output isn't correct
63 Correct 231 ms 17004 KB Output is correct
64 Incorrect 928 ms 17004 KB Output isn't correct
65 Correct 320 ms 17036 KB Output is correct
66 Incorrect 272 ms 17132 KB Output isn't correct
67 Correct 78 ms 17004 KB Output is correct
68 Incorrect 845 ms 17132 KB Output isn't correct
69 Incorrect 710 ms 17004 KB Output isn't correct
70 Incorrect 864 ms 17004 KB Output isn't correct
71 Correct 153 ms 17004 KB Output is correct
72 Incorrect 617 ms 17260 KB Output isn't correct
73 Incorrect 163 ms 17260 KB Output isn't correct
74 Execution timed out 1094 ms 17260 KB Time limit exceeded
75 Correct 224 ms 17260 KB Output is correct
76 Correct 219 ms 17260 KB Output is correct
77 Execution timed out 1051 ms 17260 KB Time limit exceeded
78 Correct 80 ms 17132 KB Output is correct
79 Execution timed out 1096 ms 17132 KB Time limit exceeded
80 Correct 213 ms 17348 KB Output is correct
81 Correct 227 ms 17260 KB Output is correct
82 Execution timed out 1084 ms 17388 KB Time limit exceeded
83 Correct 234 ms 17388 KB Output is correct
84 Execution timed out 1092 ms 17132 KB Time limit exceeded
85 Execution timed out 1090 ms 17132 KB Time limit exceeded
86 Correct 252 ms 17260 KB Output is correct
87 Execution timed out 1095 ms 17132 KB Time limit exceeded
88 Execution timed out 1043 ms 17132 KB Time limit exceeded
89 Execution timed out 1098 ms 17132 KB Time limit exceeded
90 Execution timed out 1095 ms 17132 KB Time limit exceeded
91 Execution timed out 1064 ms 17132 KB Time limit exceeded
92 Execution timed out 1098 ms 17132 KB Time limit exceeded