結果
問題 | No.2411 Reverse Directions |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-08-11 22:34:46 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,112 bytes |
コンパイル時間 | 2,518 ms |
コンパイル使用メモリ | 121,068 KB |
実行使用メモリ | 52,424 KB |
最終ジャッジ日時 | 2024-11-18 17:25:24 |
合計ジャッジ時間 | 8,155 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,820 KB |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 11 ms
8,132 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 89 ms
10,772 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 15 ms
6,820 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | WA | - |
testcase_21 | AC | 104 ms
21,460 KB |
testcase_22 | WA | - |
testcase_23 | AC | 134 ms
10,852 KB |
testcase_24 | WA | - |
testcase_25 | AC | 31 ms
10,844 KB |
testcase_26 | AC | 14 ms
6,816 KB |
testcase_27 | AC | 70 ms
10,860 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 205 ms
21,476 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; 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) { } }