結果
| 問題 | No.2411 Reverse Directions |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-11 22:22:06 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,186 bytes |
| 記録 | |
| コンパイル時間 | 2,622 ms |
| コンパイル使用メモリ | 121,756 KB |
| 実行使用メモリ | 23,296 KB |
| 最終ジャッジ日時 | 2024-11-18 16:52:25 |
| 合計ジャッジ時間 | 6,710 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 WA * 8 |
ソースコード
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[][](M, N);
auto prv = new int[][](M, N);
foreach (x; 0 .. M) {
dist[x][] = -1;
prv[x][] = -1;
}
dist[0][0] = 0;
que ~= 0;
que ~= 0;
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[xx][yy]) {
dist[xx][yy] = dist[x][y] + 1;
prv[xx][yy] = dir;
que ~= xx;
que ~= yy;
}
}
}
}
const d = dist[M - 1][N - 1];
if (~d && d <= K - (R - L) && (R - L) % 2 == 0 && (K - d) % 2 == 0) {
auto dirs = new int[d];
{
int x = M - 1, y = N - 1;
foreach_reverse (i; 0 .. d) {
const dir = prv[x][y];
dirs[i] = dir;
x -= DX[dir];
y -= DY[dir];
}
}
auto ans = new int[K];
ans[] = -1;
{
int i = 0;
foreach (j; 0 .. K) {
if (i == d || (L <= j && j < R)) {
ans[j] = (j == 0) ? dirs[0] : (ans[j - 1] ^ 2);
} else {
ans[j] = dirs[i++];
}
}
assert(i == d);
}
debug {
writeln("dirs = ", dirs);
writeln("ans = ", ans);
}
writeln("Yes");
foreach (j; 0 .. K) {
write("DRUL"[ans[j]]);
}
writeln;
} else {
writeln("No");
}
}
} catch (EOFException e) {
}
}