結果
問題 | No.402 最も海から遠い場所 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-01-30 07:40:03 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 1,561 ms / 3,000 ms |
コード長 | 3,836 bytes |
コンパイル時間 | 1,946 ms |
コンパイル使用メモリ | 156,000 KB |
実行使用メモリ | 162,932 KB |
最終ジャッジ日時 | 2024-06-13 03:54:05 |
合計ジャッジ時間 | 8,892 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,948 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 6 ms
6,944 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 29 ms
8,080 KB |
testcase_16 | AC | 41 ms
11,272 KB |
testcase_17 | AC | 487 ms
93,088 KB |
testcase_18 | AC | 1,561 ms
162,912 KB |
testcase_19 | AC | 756 ms
162,852 KB |
testcase_20 | AC | 1,076 ms
162,932 KB |
testcase_21 | AC | 764 ms
162,888 KB |
ソースコード
import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int H, W; string[] S; void main() { try { for (; ; ) { H = readInt() + 2; W = readInt() + 2; S = new string[H]; S[0] = S[H - 1] = iota(W).map!(_ => '.').to!string; foreach (x; 1 .. H - 1) { S[x] = '.' ~ readToken() ~ '.'; } /* d d d e e d d d e e d d d */ auto q = new int[H * W + (H - 1) * (W - 1)]; int qHead, qTail; auto d = new int[][](H, W); auto e = new int[][](H - 1, W - 1); foreach (x; 0 .. H) foreach (y; 0 .. W) { d[x][y] = -1; } foreach (x; 0 .. H - 1) foreach (y; 0 .. W - 1) { e[x][y] = -1; } foreach (x; 0 .. H) foreach (y; 0 .. W) { if (S[x][y] == '.') { d[x][y] = 0; q[qTail++] = x * W + y; } } for (; qHead < qTail; ) { const s = q[qHead] / (H * W); const x = q[qHead] % (H * W) / W; const y = q[qHead] % W; ++qHead; if (s == 0) { const cc = d[x][y] + 1; if (x < H - 1 && y < W - 1) { if (e[x][y] == -1) { e[x][y] = cc; q[qTail++] = H * W + x * W + y; } } if (x > 0 && y < W - 1) { if (e[x - 1][y] == -1) { e[x - 1][y] = cc; q[qTail++] = H * W + (x - 1) * W + y; } } if (x > 0 && y > 0) { if (e[x - 1][y - 1] == -1) { e[x - 1][y - 1] = cc; q[qTail++] = H * W + (x - 1) * W + (y - 1); } } if (x < H - 1 && y > 0) { if (e[x][y - 1] == -1) { e[x][y - 1] = cc; q[qTail++] = H * W + x * W + (y - 1); } } } else { const cc = e[x][y] + 1; if (d[x + 1][y + 1] == -1) { d[x + 1][y + 1] = cc; q[qTail++] = (x + 1) * W + (y + 1); } if (d[x][y + 1] == -1) { d[x][y + 1] = cc; q[qTail++] = x * W + (y + 1); } if (d[x][y] == -1) { d[x][y] = cc; q[qTail++] = x * W + y; } if (d[x + 1][y] == -1) { d[x + 1][y] = cc; q[qTail++] = (x + 1) * W + y; } } } debug { if (H <= 10) { foreach (x; 0 .. H) { writeln(d[x]); } foreach (x; 0 .. H - 1) { writeln(e[x]); } } } int ans; foreach (x; 0 .. H) foreach (y; 0 .. W) { chmax(ans, d[x][y]); } ans /= 2; writeln(ans); } } catch (EOFException e) { } }