結果

問題 No.402 最も海から遠い場所
ユーザー moyashi_senpaimoyashi_senpai
提出日時 2016-07-23 00:29:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,029 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 81,324 KB
実行使用メモリ 499,672 KB
最終ジャッジ日時 2024-04-24 03:18:43
合計ジャッジ時間 16,212 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 366 ms
426,112 KB
testcase_01 WA -
testcase_02 AC 356 ms
426,112 KB
testcase_03 AC 360 ms
426,240 KB
testcase_04 AC 358 ms
426,112 KB
testcase_05 AC 363 ms
425,984 KB
testcase_06 AC 359 ms
426,240 KB
testcase_07 AC 358 ms
426,112 KB
testcase_08 AC 362 ms
426,112 KB
testcase_09 AC 360 ms
426,112 KB
testcase_10 WA -
testcase_11 AC 357 ms
426,112 KB
testcase_12 WA -
testcase_13 AC 369 ms
426,368 KB
testcase_14 AC 362 ms
426,368 KB
testcase_15 AC 400 ms
427,136 KB
testcase_16 AC 406 ms
427,648 KB
testcase_17 AC 1,056 ms
443,988 KB
testcase_18 AC 1,894 ms
429,952 KB
testcase_19 AC 1,157 ms
499,672 KB
testcase_20 AC 1,632 ms
426,240 KB
testcase_21 AC 1,232 ms
463,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |         scanf("%d %d%*c", &h, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:33:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |                         scanf("%c", &c);
      |                         ~~~~~^~~~~~~~~~
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf("%*c");
      |                 ~~~~~^~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))

typedef vector<int> Ivec;
typedef pair<int, int> Pos;

const pair<int, int> dir[8] = { {0,1},{1,1}, {1,0},{0,-1},{-1,-1},{1,-1},{-1,1}, {-1,0} };

#define MAX(a,b) (((a)>(b))?(a):(b))

#define Chebi(a,b) (MAX(abs(a.first-b.first),abs(a.second-b.second))) 
int main() {
	int h, w;
	scanf("%d %d%*c", &h, &w);
	int map[3004][30004] = {};
	Pos poss[3004][3004];
	queue<Pos> wf;
	for (int i = 2; h + 1 >= i; i++) {
		for (int j = 2; w + 1 >= j; j++) {
			char c;
			scanf("%c", &c);
			map[i][j] = c == '#' ? 1 : 0;
			if (c == '.') {
				wf.push({ i,j });
				poss[i][j] = { i,j };
			}
		}
		scanf("%*c");
	}
	for (int i = 1; h + 2 >= i; i++) {
		wf.push({ i, 1 });
		wf.push({ i, h+1 });
		poss[i][1] = { i,1 };
		poss[i][h+2] = {i, h + 2 };
	}
	for (int i = 1; w + 2 >= i; i++) {
		wf.push({ 1,i });
		wf.push({w+2,i });
		poss[1][i] = { 1,i};
		poss[w+2][i] = {w + 2,i};
	}
	while (!wf.empty()) {
		Pos sea = wf.front();
		wf.pop();
		for (int i = 0; 8 > i; i++) {
			Pos tar = { sea.first + dir[i].first ,sea.second + dir[i].second };
			if (map[tar.first][tar.second] == 1) {
				if (poss[tar.first][tar.second].first == 0 || (Chebi(tar, poss[sea.first][sea.second]) < Chebi(tar, poss[tar.first][tar.second]))) {
					if (poss[tar.first][tar.second].first == 0 || poss[tar.first][tar.second].first != poss[sea.first][sea.second].first || poss[tar.first][tar.second].second != poss[sea.first][sea.second].second)
					{
						poss[tar.first][tar.second] = poss[sea.first][sea.second];
						wf.push(tar);
					}
				}
			}
		}
	}
	int maxim = -1;
	for (int i = 2; h + 1 >= i; i++) {
		for (int j = 2; w + 1 >= j; j++) {
			if (map[i][j] != 1)continue;
			Pos tar = { i,j };
			maxim = max(maxim, Chebi(poss[i][j], tar));
		}
	}
	printf("%d", maxim);
	return 0;
}
0