結果

問題 No.402 最も海から遠い場所
ユーザー simansiman
提出日時 2021-10-08 02:30:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 3,000 ms
コード長 1,597 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 108,324 KB
実行使用メモリ 47,448 KB
最終ジャッジ日時 2023-09-30 09:13:08
合計ジャッジ時間 3,519 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
38,624 KB
testcase_01 AC 11 ms
38,756 KB
testcase_02 AC 10 ms
38,696 KB
testcase_03 AC 11 ms
38,664 KB
testcase_04 AC 11 ms
38,620 KB
testcase_05 AC 11 ms
38,676 KB
testcase_06 AC 10 ms
38,740 KB
testcase_07 AC 10 ms
38,668 KB
testcase_08 AC 10 ms
38,608 KB
testcase_09 AC 11 ms
38,668 KB
testcase_10 AC 10 ms
38,676 KB
testcase_11 AC 11 ms
38,680 KB
testcase_12 AC 10 ms
38,764 KB
testcase_13 AC 12 ms
38,716 KB
testcase_14 AC 10 ms
38,784 KB
testcase_15 AC 17 ms
39,000 KB
testcase_16 AC 19 ms
39,076 KB
testcase_17 AC 146 ms
42,680 KB
testcase_18 AC 228 ms
47,376 KB
testcase_19 AC 194 ms
47,440 KB
testcase_20 AC 221 ms
47,448 KB
testcase_21 AC 197 ms
47,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_H = 3000;
const int MAX_W = 3000;

int max_dist[MAX_H + 2][MAX_W + 2];

struct Node {
  int by;
  int bx;
  int y;
  int x;
  int dist;

  Node(int by = -1, int bx = -1, int y = -1, int x = -1, int dist = -1) {
    this->by = by;
    this->bx = bx;
    this->y = y;
    this->x = x;
    this->dist = dist;
  }

  bool operator>(const Node &n) const {
    return dist > n.dist;
  }
};

int main() {
  int H, W;
  cin >> H >> W;
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  memset(max_dist, -1, sizeof(max_dist));
  vector<string> S;

  for (int y = 1; y <= H; ++y) {
    string row;
    cin >> row;
    S.push_back(row);
    for (int x = 1; x <= W; ++x) {
      if (row[x - 1] == '.') {
        max_dist[y][x] = 0;
      }
    }
  }

  for (int y = 0; y < H + 2; ++y) {
    for (int x = 0; x < W + 2; ++x) {
      if (y == 0 || x == 0 || y == H + 1 || x == W + 1) {
        max_dist[y][x] = 0;
      }
    }
  }

  int ans = 1;

  for (int y = 1; y <= H; ++y) {
    for (int x = 1; x <= W; ++x) {
      if (S[y - 1][x - 1] == '.') continue;

      int d1 = max(0, max_dist[y - 1][x - 1]);
      int d2 = max(0, max_dist[y - 1][x]);
      int d3 = max(0, max_dist[y][x - 1]);

      max_dist[y][x] = min(d1, min(d2, d3)) + 1;
      ans = max(ans, max_dist[y][x]);
    }
  }

  cout << (ans + 1) / 2 << endl;

  return 0;
}
0