結果

問題 No.2411 Reverse Directions
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-08-11 22:22:06
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 3,186 bytes
コンパイル時間 914 ms
コンパイル使用メモリ 119,808 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-29 13:22:48
合計ジャッジ時間 5,355 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 207 ms
13,312 KB
testcase_11 WA -
testcase_12 AC 172 ms
22,400 KB
testcase_13 AC 41 ms
10,880 KB
testcase_14 AC 60 ms
11,520 KB
testcase_15 WA -
testcase_16 AC 11 ms
5,376 KB
testcase_17 AC 58 ms
8,576 KB
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 43 ms
10,880 KB
testcase_21 AC 73 ms
13,696 KB
testcase_22 AC 119 ms
11,776 KB
testcase_23 AC 69 ms
18,176 KB
testcase_24 AC 142 ms
21,376 KB
testcase_25 AC 22 ms
7,040 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 34 ms
10,752 KB
testcase_28 WA -
testcase_29 AC 197 ms
23,296 KB
testcase_30 WA -
testcase_31 AC 98 ms
21,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
  }
}
0