結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2016-07-24 12:30:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,552 bytes |
| コンパイル時間 | 665 ms |
| コンパイル使用メモリ | 71,816 KB |
| 実行使用メモリ | 818,136 KB |
| 最終ジャッジ日時 | 2024-11-06 15:49:08 |
| 合計ジャッジ時間 | 5,871 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 MLE * 1 -- * 2 |
コンパイルメッセージ
main.cpp: In function ‘void input()’:
main.cpp:28:48: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | for (int i = 1; i < h - 1; i++) { scanf("%s", s[i] + 1); s[i][w-1] = '.'; }
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
//サンプルがやさしい(な阪関)
#include <iostream>
#include <algorithm>
#include <tuple>
#include <queue>
#include <cstdio>
using namespace std;
int h, w;
char s[3002][3002];
int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int cost[3002][3002];
void input() {
//番兵する
cin >> h >> w;
h += 2;
w += 2;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
s[i][j] = '.';
}
}
for (int i = 1; i < h - 1; i++) { scanf("%s", s[i] + 1); s[i][w-1] = '.'; }
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cost[i][j] = 1145141919;
}
}
}
bool is_range(int y, int x) {
return (0 <= y && y < h && 0 <= x && x < w);
}
void bfs() {
typedef tuple<int, int, int> T; //cost, y, x
static queue<T> que;
//全ての海を始点にする
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '.') {
que.push(T(0, i, j));
}
}
}
while (!que.empty()) {
T now = que.front();
que.pop();
int cst = get<0>(now);
int y = get<1>(now);
int x = get<2>(now);
if (cost[y][x] <= cst) {
continue;
}
cost[y][x] = cst;
for (int dir = 0; dir < 8; dir++) {
int ny = y + dy[dir];
int nx = x + dx[dir];
if (is_range(ny, nx)) {
que.push(T(cst + 1, ny, nx));
}
}
}
}
int answer() {
int ans = -1;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
ans = max(ans, cost[i][j]);
}
}
return ans;
}
int main() {
input();
bfs();
cout << answer() << endl;
return 0;
}
startcpp