제출 #74666

#제출 시각아이디문제언어결과실행 시간메모리
74666arman_ferdousMecho (IOI09_mecho)C++17
6 / 100
702 ms66560 KiB
#include <bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
typedef pair<int,int> ii;
const int N = 804;
const int inf = 2e9;

int n, step, d[N][N], dist[N][N];
char s[N][N];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

queue<ii> q;
ii mecho, home;

bool can(int t) {
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			dist[i][j] = inf;

	q.push(mecho);
	dist[mecho.xx][mecho.yy] = 0;
	while(!q.empty()) {
		ii u = q.front(); q.pop();
		for(int i = 0; i < 4; i++) {
			ii v = {u.xx + dx[i], u.yy + dy[i]};

			if(min(v.xx,v.yy) < 0 || n <= max(v.xx,v.yy)) continue;
			char cell = s[v.xx][v.yy];
			if(cell == 'T' || cell == 'M' || cell == 'H') continue;
			int arrival = ceil((double)(dist[u.xx][u.yy] + 1.) / step) + t;
			if(arrival > d[v.xx][v.yy] || dist[u.xx][u.yy] + 1 > dist[v.xx][v.yy]) continue;
			dist[v.xx][v.yy] = dist[u.xx][u.yy] + 1;
			q.push(v);
		}
	}
	return dist[home.xx][home.yy] != inf;
}

int main() {
	scanf("%d %d", &n, &step);
	for(int i = 0; i < n; i++)
		scanf(" %s", s[i]);

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) {
			d[i][j] = inf;
			if(s[i][j] == 'M') mecho = {i,j};
			else if(s[i][j] == 'D') home = {i,j};
		}

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) 
			if(s[i][j] == 'H') {
				q.push({i,j});
				d[i][j] = 0;
			}

	while(!q.empty()) {
		ii u = q.front(); q.pop();
		for(int i = 0; i < 4; i++) {
			ii v = {u.xx + dx[i], u.yy + dy[i]};

			if(min(v.xx,v.yy) < 0 || n <= max(v.xx,v.yy)) continue;
			char cell = s[v.xx][v.yy];
			if(cell == 'T' || cell == 'D' || cell == 'H') continue;
			if(d[v.xx][v.yy] < d[u.xx][u.yy] + 1) continue;
			d[v.xx][v.yy] = d[u.xx][u.yy] + 1;
			q.push(v);
		}
	}
	int lo = 0, hi = n+n, ans = -1;
		while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		if(can(mid)) ans = mid, lo = mid+1;
		else hi = mid-1;
	} printf("%d\n", ans);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp: In function 'int main()':
mecho.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &step);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
mecho.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", s[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...