結果
問題 | No.2411 Reverse Directions |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-08-11 22:35:33 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 295 ms / 2,000 ms |
コード長 | 4,139 bytes |
コンパイル時間 | 2,344 ms |
コンパイル使用メモリ | 126,388 KB |
実行使用メモリ | 52,292 KB |
最終ジャッジ日時 | 2024-11-18 17:27:12 |
合計ジャッジ時間 | 5,700 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 75 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 11 ms
8,400 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 295 ms
23,888 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 251 ms
22,360 KB |
testcase_13 | AC | 90 ms
10,792 KB |
testcase_14 | AC | 74 ms
11,476 KB |
testcase_15 | AC | 23 ms
6,816 KB |
testcase_16 | AC | 17 ms
6,816 KB |
testcase_17 | AC | 85 ms
11,964 KB |
testcase_18 | AC | 37 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,816 KB |
testcase_20 | AC | 69 ms
10,932 KB |
testcase_21 | AC | 115 ms
21,472 KB |
testcase_22 | AC | 175 ms
11,456 KB |
testcase_23 | AC | 147 ms
10,820 KB |
testcase_24 | AC | 246 ms
52,292 KB |
testcase_25 | AC | 34 ms
10,888 KB |
testcase_26 | AC | 15 ms
6,820 KB |
testcase_27 | AC | 74 ms
10,852 KB |
testcase_28 | AC | 154 ms
13,048 KB |
testcase_29 | AC | 285 ms
24,188 KB |
testcase_30 | AC | 193 ms
23,084 KB |
testcase_31 | AC | 233 ms
21,412 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, 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; } 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)); } enum DX = [+1, 0, -1, 0]; enum DY = [0, +1, 0, -1]; void main() { try { for (; ; ) { const M = readInt; const N = readInt; const K = readInt; const L = readInt - 1; const R = readInt; auto S = new string[M]; foreach (x; 0 .. M) { S[x] = readToken; } DList!int que; auto dist = new int[][][](2, M, N); auto prv = new int[][][](2, M, N); foreach (h; 0 .. 2) { foreach (x; 0 .. M) { dist[h][x][] = -1; prv[h][x][] = -1; } int sx, sy; if (h == 0) { sx = 0; sy = 0; } else { sx = M - 1; sy = N - 1; } dist[h][sx][sy] = 0; que ~= sx; que ~= sy; for (; !que.empty; ) { const x = que.front; que.removeFront; const y = que.front; que.removeFront; foreach (dir; 0 .. 4) { int xx = x + DX[dir]; int yy = y + DY[dir]; if (0 <= xx && xx < M && 0 <= yy && yy < N && S[xx][yy] == '.') { if (!~dist[h][xx][yy]) { dist[h][xx][yy] = dist[h][x][y] + 1; prv[h][xx][yy] = dir; que ~= xx; que ~= yy; } } } } debug { foreach (x; 0 .. M) { writeln(dist[h][x]); } } } bool check(int d, int l) { return (~d && d <= l && (l - d) % 2 == 0); } foreach (x0; 0 .. M) foreach (y0; 0 .. N) if (S[x0][y0] == '.') { const d0 = dist[0][x0][y0]; const d1 = dist[1][x0][y0]; foreach (k; 0 .. 2) { bool ok = true; foreach (dir; [k, k ^ 2]) { const xx = x0 + DX[dir]; const yy = y0 + DY[dir]; ok = ok && (0 <= xx && xx < M && 0 <= yy && yy < N && S[xx][yy] == '.'); } ok = ok && check(d0, L); ok = ok && ((R - L) % 2 == 0); ok = ok && check(d1, K - R); if (ok) { int[][2] fss; foreach (h; 0 .. 2) { int x = x0, y = y0; for (; ; ) { const dir = prv[h][x][y]; if (!~dir) break; fss[h] ~= dir; x -= DX[dir]; y -= DY[dir]; } } fss[0].reverse; fss[1][] ^= 2; debug { writeln("fss = ", fss); } auto ans = new int[K]; ans[] = -1; ans[0 .. d0] = fss[0][]; ans[K - d1 .. K] = fss[1][]; foreach (j; d0 .. K - d1) { ans[j] = ((j - d0) & 1) ? (k ^ 2) : k; } writeln("Yes"); foreach (j; 0 .. K) { write("DRUL"[ans[j]]); } writeln; goto found; } } } writeln("No"); found: } } catch (EOFException e) { } }