結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2016-06-24 03:06:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 584 ms / 3,000 ms |
コード長 | 1,324 bytes |
コンパイル時間 | 1,037 ms |
コンパイル使用メモリ | 67,604 KB |
実行使用メモリ | 115,884 KB |
最終ジャッジ日時 | 2024-11-06 10:09:02 |
合計ジャッジ時間 | 4,136 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
#include <iostream> #include <stdio.h> #include <algorithm> #include <queue> using namespace std; int W, H; int dist[3010][3010] = { 0 }; char s[3010]; int main(void) { cin >> H >> W; queue<int> Q; for (int i = 2; i <= H + 1; i++) { scanf("%s", s); for (int j = 2; j <= W + 1; j++) { if (s[j - 2] == '#') { dist[i][j] = 1510; } else { Q.push(0); Q.push(j); Q.push(i); } } } for (int i = 2; i <= H + 1; i++) { Q.push(0); Q.push(1); Q.push(i); Q.push(0); Q.push(W + 2); Q.push(i); } for (int i = 2; i <= W + 1; i++) { Q.push(0); Q.push(i); Q.push(1); Q.push(0); Q.push(i); Q.push(H + 2); } int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 }; int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 }; int ans = 0; while (Q.size()) { int t = Q.front(); Q.pop(); int x = Q.front(); Q.pop(); int y = Q.front(); Q.pop(); for (int i = 0; i < 8; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (dist[ny][nx] > t + 1) { ans = max(ans, dist[ny][nx] = t + 1); Q.push(t + 1); Q.push(nx); Q.push(ny); } } } cout << ans << endl; return 0; }