답안 #341031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341031 2020-12-28T22:44:34 Z peuch Mecho (IOI09_mecho) C++17
84 / 100
299 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("%d\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] = 1e18;
			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] + s;
			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 >= 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 = 1e8 + 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:32:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   32 |  printf("%d\n", bb());
      |          ~^     ~~~~
      |           |       |
      |           int     long long int
      |          %lld
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]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Correct 235 ms 17004 KB Output is correct
8 Correct 1 ms 492 KB Output is 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 1 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 620 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 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 1004 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 2 ms 1260 KB Output is correct
28 Correct 2 ms 1260 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 2 ms 1260 KB Output is correct
31 Correct 2 ms 1408 KB Output is correct
32 Correct 2 ms 1388 KB Output is correct
33 Correct 17 ms 6764 KB Output is correct
34 Correct 20 ms 6764 KB Output is correct
35 Correct 39 ms 6764 KB Output is correct
36 Correct 22 ms 8044 KB Output is correct
37 Correct 23 ms 8064 KB Output is correct
38 Correct 52 ms 8044 KB Output is correct
39 Correct 27 ms 9324 KB Output is correct
40 Correct 28 ms 9324 KB Output is correct
41 Correct 71 ms 9540 KB Output is correct
42 Correct 33 ms 10732 KB Output is correct
43 Correct 37 ms 10744 KB Output is correct
44 Correct 90 ms 10780 KB Output is correct
45 Correct 39 ms 11756 KB Output is correct
46 Correct 43 ms 11756 KB Output is correct
47 Correct 110 ms 11756 KB Output is correct
48 Correct 51 ms 12908 KB Output is correct
49 Correct 57 ms 12780 KB Output is correct
50 Correct 134 ms 12780 KB Output is correct
51 Correct 55 ms 13804 KB Output is correct
52 Correct 65 ms 13804 KB Output is correct
53 Correct 170 ms 13804 KB Output is correct
54 Correct 67 ms 14828 KB Output is correct
55 Correct 71 ms 14828 KB Output is correct
56 Correct 198 ms 14848 KB Output is correct
57 Correct 83 ms 15852 KB Output is correct
58 Correct 87 ms 15852 KB Output is correct
59 Correct 247 ms 15972 KB Output is correct
60 Correct 98 ms 17004 KB Output is correct
61 Correct 107 ms 17004 KB Output is correct
62 Correct 299 ms 17080 KB Output is correct
63 Correct 189 ms 17156 KB Output is correct
64 Correct 256 ms 17004 KB Output is correct
65 Correct 286 ms 17004 KB Output is correct
66 Correct 244 ms 17004 KB Output is correct
67 Correct 79 ms 17004 KB Output is correct
68 Correct 144 ms 16972 KB Output is correct
69 Correct 138 ms 17004 KB Output is correct
70 Correct 127 ms 17032 KB Output is correct
71 Correct 131 ms 17004 KB Output is correct
72 Incorrect 126 ms 17132 KB Output isn't correct
73 Incorrect 152 ms 17260 KB Output isn't correct
74 Correct 206 ms 17280 KB Output is correct
75 Correct 184 ms 17388 KB Output is correct
76 Correct 189 ms 17260 KB Output is correct
77 Correct 223 ms 17316 KB Output is correct
78 Correct 81 ms 17260 KB Output is correct
79 Correct 174 ms 17132 KB Output is correct
80 Correct 177 ms 17132 KB Output is correct
81 Correct 181 ms 17132 KB Output is correct
82 Correct 175 ms 17132 KB Output is correct
83 Correct 189 ms 17132 KB Output is correct
84 Correct 215 ms 17324 KB Output is correct
85 Correct 181 ms 17388 KB Output is correct
86 Correct 195 ms 17260 KB Output is correct
87 Correct 214 ms 17132 KB Output is correct
88 Correct 192 ms 17164 KB Output is correct
89 Correct 233 ms 17188 KB Output is correct
90 Correct 211 ms 17132 KB Output is correct
91 Correct 215 ms 17164 KB Output is correct
92 Correct 227 ms 17260 KB Output is correct