답안 #835385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835385 2023-08-23T13:59:35 Z mohammad_kilani Mecho (IOI09_mecho) C++17
4 / 100
20 ms 3792 KB
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000010

const int N = 810;

int n , s;

char grid[N][N];

int cost[N][N];

int dr[] = {0 , 1,  0 , -1};
int dc[] = {1 , 0 , -1 , 0};

int sr , sc , er , ec;

int cost2[N][N];

void BFSH(){
	queue < pair< int , int > > q;
	memset(cost , -1, sizeof(cost));
	for(int i = 0;i < n;i++){
		for(int j = 0 ;j < n;j++){
			if(grid[i][j] == 'H'){
				q.push(make_pair(i , j));
				cost[i][j] = 0;
			}
		}
	}
	int row , col;
	while(!q.empty()){
		row = q.front().first;
		col = q.front().second;
		q.pop();
		for(int nr , nc , i = 0 ;i < 4;i++){
			nr = row + dr[i];
			nc = col + dc[i];
			if(nr < 0 || nr >= n || nc < 0 || nc >= n || grid[nr][nc] == 'T' || grid[nr][nc] == 'D' || cost[nr][nc] != -1) continue;
			cost[nr][nc] = cost[row][col] + 1;
			q.push(make_pair(nr , nc));
		}
	}
}

bool check(int mid){
	for(int i = 0 ;i < n;i++) for(int j = 0 ;j < n;j++) cost2[i][j] = -1;
	cost2[sr][sc] = mid * s;
	queue < pair< int , int > > q;
	q.push(make_pair(sr, sc));
	int row , col;
	while(!q.empty()){
		row = q.front().first;
		col = q.front().second;
		q.pop();
		if(cost2[row][col] >= cost[row][col] * s) continue;
		for(int nr , nc , i = 0 ;i < 4;i++){
			nr = row + dr[i];
			nc = col + dc[i];
			if(nr < 0 || nr >= n || nc < 0 || nc >= n || grid[nr][nc] == 'T' || cost2[nr][nc] != -1) continue;
			cost2[nr][nc] = cost2[row][col] + 1;
			q.push(make_pair(nr , nc));
		}
	}
	if(cost2[er][ec] == -1)
		return false;
	return true;
}

int main(){
	scanf("%d%d",&n,&s);
	for(int i = 0 ;i < n;i++){
		scanf("%s",grid[i]);
		for(int j = 0 ;j < n;j++){
			if(grid[i][j] == 'M')
				sr = i , sc = j;
			if(grid[i][j] == 'D')
				er = i , ec = j;
		}
	}
	BFSH();

	int low = 0 , high = cost[er][ec] - 1 , mid , ans = -1;

	while(high >= low){
		mid = (low + high) / 2;
		if(check(mid))
			ans = mid , low = mid + 1;
		else
			high = mid - 1;
	}
	cout << ans << endl;
	return 0;
} 

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |  scanf("%d%d",&n,&s);
      |  ~~~~~^~~~~~~~~~~~~~
mecho.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%s",grid[i]);
      |   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2772 KB Output isn't correct
2 Incorrect 1 ms 2772 KB Output isn't correct
3 Incorrect 1 ms 2772 KB Output isn't correct
4 Incorrect 1 ms 2772 KB Output isn't correct
5 Incorrect 1 ms 2772 KB Output isn't correct
6 Incorrect 1 ms 2860 KB Output isn't correct
7 Incorrect 15 ms 3584 KB Output isn't correct
8 Correct 2 ms 2768 KB Output is correct
9 Incorrect 1 ms 2772 KB Output isn't correct
10 Incorrect 1 ms 2772 KB Output isn't correct
11 Incorrect 1 ms 2772 KB Output isn't correct
12 Incorrect 1 ms 2900 KB Output isn't correct
13 Incorrect 1 ms 2900 KB Output isn't correct
14 Correct 1 ms 2900 KB Output is correct
15 Incorrect 1 ms 2772 KB Output isn't correct
16 Incorrect 1 ms 2772 KB Output isn't correct
17 Incorrect 1 ms 2772 KB Output isn't correct
18 Incorrect 1 ms 2772 KB Output isn't correct
19 Incorrect 1 ms 2900 KB Output isn't correct
20 Incorrect 1 ms 2900 KB Output isn't correct
21 Incorrect 1 ms 2900 KB Output isn't correct
22 Incorrect 1 ms 2900 KB Output isn't correct
23 Incorrect 1 ms 2900 KB Output isn't correct
24 Incorrect 1 ms 2900 KB Output isn't correct
25 Incorrect 1 ms 2900 KB Output isn't correct
26 Incorrect 1 ms 2900 KB Output isn't correct
27 Incorrect 1 ms 2900 KB Output isn't correct
28 Incorrect 1 ms 2900 KB Output isn't correct
29 Incorrect 1 ms 2900 KB Output isn't correct
30 Incorrect 1 ms 2900 KB Output isn't correct
31 Incorrect 1 ms 2900 KB Output isn't correct
32 Incorrect 1 ms 2900 KB Output isn't correct
33 Incorrect 3 ms 3028 KB Output isn't correct
34 Incorrect 3 ms 3028 KB Output isn't correct
35 Incorrect 3 ms 3028 KB Output isn't correct
36 Incorrect 3 ms 3156 KB Output isn't correct
37 Incorrect 3 ms 3156 KB Output isn't correct
38 Incorrect 4 ms 3156 KB Output isn't correct
39 Incorrect 4 ms 3160 KB Output isn't correct
40 Incorrect 3 ms 3156 KB Output isn't correct
41 Incorrect 4 ms 3156 KB Output isn't correct
42 Incorrect 4 ms 3156 KB Output isn't correct
43 Incorrect 4 ms 3156 KB Output isn't correct
44 Incorrect 5 ms 3156 KB Output isn't correct
45 Incorrect 5 ms 3312 KB Output isn't correct
46 Incorrect 4 ms 3284 KB Output isn't correct
47 Incorrect 6 ms 3316 KB Output isn't correct
48 Incorrect 5 ms 3284 KB Output isn't correct
49 Incorrect 5 ms 3284 KB Output isn't correct
50 Incorrect 7 ms 3248 KB Output isn't correct
51 Incorrect 6 ms 3284 KB Output isn't correct
52 Incorrect 5 ms 3284 KB Output isn't correct
53 Incorrect 7 ms 3284 KB Output isn't correct
54 Incorrect 7 ms 3412 KB Output isn't correct
55 Incorrect 6 ms 3412 KB Output isn't correct
56 Incorrect 9 ms 3584 KB Output isn't correct
57 Incorrect 8 ms 3412 KB Output isn't correct
58 Incorrect 7 ms 3412 KB Output isn't correct
59 Incorrect 10 ms 3472 KB Output isn't correct
60 Incorrect 8 ms 3412 KB Output isn't correct
61 Incorrect 8 ms 3412 KB Output isn't correct
62 Incorrect 11 ms 3508 KB Output isn't correct
63 Incorrect 17 ms 3412 KB Output isn't correct
64 Incorrect 16 ms 3508 KB Output isn't correct
65 Incorrect 16 ms 3508 KB Output isn't correct
66 Incorrect 17 ms 3512 KB Output isn't correct
67 Correct 17 ms 3512 KB Output is correct
68 Incorrect 18 ms 3540 KB Output isn't correct
69 Incorrect 19 ms 3536 KB Output isn't correct
70 Incorrect 19 ms 3540 KB Output isn't correct
71 Incorrect 18 ms 3528 KB Output isn't correct
72 Incorrect 18 ms 3540 KB Output isn't correct
73 Incorrect 15 ms 3792 KB Output isn't correct
74 Incorrect 18 ms 3792 KB Output isn't correct
75 Incorrect 15 ms 3660 KB Output isn't correct
76 Incorrect 15 ms 3792 KB Output isn't correct
77 Incorrect 17 ms 3784 KB Output isn't correct
78 Correct 15 ms 3668 KB Output is correct
79 Incorrect 15 ms 3668 KB Output isn't correct
80 Incorrect 15 ms 3764 KB Output isn't correct
81 Incorrect 15 ms 3668 KB Output isn't correct
82 Incorrect 15 ms 3668 KB Output isn't correct
83 Incorrect 15 ms 3728 KB Output isn't correct
84 Incorrect 20 ms 3724 KB Output isn't correct
85 Incorrect 15 ms 3724 KB Output isn't correct
86 Incorrect 15 ms 3728 KB Output isn't correct
87 Incorrect 15 ms 3708 KB Output isn't correct
88 Incorrect 15 ms 3664 KB Output isn't correct
89 Incorrect 15 ms 3676 KB Output isn't correct
90 Incorrect 15 ms 3596 KB Output isn't correct
91 Incorrect 15 ms 3648 KB Output isn't correct
92 Incorrect 15 ms 3580 KB Output isn't correct