Submission #341022

# Submission time Handle Problem Language Result Execution time Memory
341022 2020-12-28T22:21:52 Z peuch Mecho (IOI09_mecho) C++17
32 / 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] + 1) / 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 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Execution timed out 1094 ms 17004 KB Time limit exceeded
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 640 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 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 704 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 748 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Incorrect 2 ms 1024 KB Output isn't correct
23 Correct 1 ms 1004 KB Output is correct
24 Incorrect 2 ms 1004 KB Output isn't correct
25 Correct 2 ms 1132 KB Output is correct
26 Incorrect 3 ms 1132 KB Output isn't correct
27 Correct 2 ms 1260 KB Output is correct
28 Incorrect 3 ms 1260 KB Output isn't correct
29 Correct 3 ms 1260 KB Output is correct
30 Incorrect 3 ms 1260 KB Output isn't correct
31 Correct 2 ms 1388 KB Output is correct
32 Incorrect 3 ms 1388 KB Output isn't correct
33 Correct 21 ms 6764 KB Output is correct
34 Incorrect 71 ms 6836 KB Output isn't correct
35 Incorrect 134 ms 6764 KB Output isn't correct
36 Correct 29 ms 8092 KB Output is correct
37 Incorrect 77 ms 8044 KB Output isn't correct
38 Incorrect 182 ms 8172 KB Output isn't correct
39 Correct 34 ms 9324 KB Output is correct
40 Incorrect 100 ms 9324 KB Output isn't correct
41 Incorrect 280 ms 9452 KB Output isn't correct
42 Correct 42 ms 10732 KB Output is correct
43 Incorrect 111 ms 10900 KB Output isn't correct
44 Incorrect 378 ms 10780 KB Output isn't correct
45 Correct 52 ms 11776 KB Output is correct
46 Incorrect 177 ms 11756 KB Output isn't correct
47 Incorrect 460 ms 11884 KB Output isn't correct
48 Correct 67 ms 12780 KB Output is correct
49 Incorrect 178 ms 12908 KB Output isn't correct
50 Incorrect 482 ms 12908 KB Output isn't correct
51 Correct 80 ms 13932 KB Output is correct
52 Incorrect 209 ms 13888 KB Output isn't correct
53 Incorrect 597 ms 13804 KB Output isn't correct
54 Correct 108 ms 14828 KB Output is correct
55 Incorrect 235 ms 14928 KB Output isn't correct
56 Incorrect 760 ms 14828 KB Output isn't correct
57 Correct 111 ms 15852 KB Output is correct
58 Incorrect 288 ms 15852 KB Output isn't correct
59 Incorrect 853 ms 15852 KB Output isn't correct
60 Correct 131 ms 17004 KB Output is correct
61 Incorrect 332 ms 17004 KB Output isn't correct
62 Incorrect 959 ms 17132 KB Output isn't correct
63 Correct 232 ms 17004 KB Output is correct
64 Incorrect 938 ms 17004 KB Output isn't correct
65 Correct 336 ms 17004 KB Output is correct
66 Correct 255 ms 17004 KB Output is correct
67 Correct 80 ms 17004 KB Output is correct
68 Incorrect 858 ms 17132 KB Output isn't correct
69 Incorrect 729 ms 17132 KB Output isn't correct
70 Incorrect 872 ms 17004 KB Output isn't correct
71 Correct 158 ms 17004 KB Output is correct
72 Incorrect 625 ms 17132 KB Output isn't correct
73 Incorrect 168 ms 17260 KB Output isn't correct
74 Execution timed out 1093 ms 17260 KB Time limit exceeded
75 Correct 228 ms 17260 KB Output is correct
76 Correct 211 ms 17300 KB Output is correct
77 Execution timed out 1084 ms 17388 KB Time limit exceeded
78 Correct 79 ms 17132 KB Output is correct
79 Execution timed out 1094 ms 17132 KB Time limit exceeded
80 Correct 210 ms 17260 KB Output is correct
81 Correct 226 ms 17260 KB Output is correct
82 Execution timed out 1083 ms 17132 KB Time limit exceeded
83 Correct 238 ms 17132 KB Output is correct
84 Execution timed out 1090 ms 17260 KB Time limit exceeded
85 Execution timed out 1099 ms 17132 KB Time limit exceeded
86 Correct 249 ms 17132 KB Output is correct
87 Execution timed out 1088 ms 17216 KB Time limit exceeded
88 Execution timed out 1049 ms 17132 KB Time limit exceeded
89 Execution timed out 1083 ms 17292 KB Time limit exceeded
90 Execution timed out 1090 ms 17132 KB Time limit exceeded
91 Execution timed out 1091 ms 17260 KB Time limit exceeded
92 Execution timed out 1081 ms 17260 KB Time limit exceeded