結果
問題 | No.2411 Reverse Directions |
ユーザー | kakel-san |
提出日時 | 2023-08-11 22:51:32 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,274 bytes |
コンパイル時間 | 3,605 ms |
コンパイル使用メモリ | 115,076 KB |
実行使用メモリ | 57,712 KB |
最終ジャッジ日時 | 2024-11-18 18:00:07 |
合計ジャッジ時間 | 28,959 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
34,288 KB |
testcase_01 | AC | 33 ms
34,196 KB |
testcase_02 | AC | 34 ms
33,952 KB |
testcase_03 | AC | 33 ms
47,120 KB |
testcase_04 | AC | 52 ms
33,496 KB |
testcase_05 | AC | 33 ms
49,280 KB |
testcase_06 | AC | 33 ms
34,032 KB |
testcase_07 | AC | 41 ms
36,252 KB |
testcase_08 | AC | 32 ms
29,652 KB |
testcase_09 | AC | 33 ms
49,320 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 34 ms
25,460 KB |
testcase_14 | TLE | - |
testcase_15 | WA | - |
testcase_16 | AC | 35 ms
24,916 KB |
testcase_17 | TLE | - |
testcase_18 | WA | - |
testcase_19 | AC | 34 ms
25,300 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 32 ms
23,092 KB |
testcase_24 | WA | - |
testcase_25 | AC | 33 ms
24,880 KB |
testcase_26 | AC | 37 ms
27,392 KB |
testcase_27 | TLE | - |
testcase_28 | WA | - |
testcase_29 | TLE | - |
testcase_30 | WA | - |
testcase_31 | AC | 58 ms
31,864 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (h, w, k, l, r) = (c[0], c[1], c[2], c[3], c[4]); var map = SList(h); if ((r - l) % 2 == 0 || l == 1 || r == k) { WriteLine("No"); return; } var vrev = new bool[h][]; for (var i = 0; i < vrev.Length; ++i) { vrev[i] = new bool[w]; for (var j = 0; j < vrev[i].Length; ++j) { if (i > 0 && i + 1 < h && map[i - 1][j] == '.' && map[i][j] == '.' && map[i + 1][j] == '.') vrev[i][j] = true; } } var hrev = new bool[h][]; for (var i = 0; i < hrev.Length; ++i) { hrev[i] = new bool[w]; for (var j = 1; j + 1 < hrev[i].Length; ++j) { if (map[i][j - 1] == '.' && map[i][j] == '.' && map[i][j + 1] == '.') hrev[i][j] = true; } } var slen = new int[h][]; for (var i = 0; i < slen.Length; ++i) slen[i] = Enumerable.Repeat(int.MaxValue, w).ToArray(); slen[0][0] = 0; var q = new Queue<(int x, int y)>(); q.Enqueue((0, 0)); while (q.Count > 0) { var cur = q.Dequeue(); for (var i = 0; i < mx.Length; ++i) { var nx = cur.x + mx[i]; var ny = cur.y + my[i]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (map[nx][ny] != '.') continue; if (slen[nx][ny] <= slen[cur.x][cur.y] + 1) continue; slen[nx][ny] = slen[cur.x][cur.y] + 1; q.Enqueue((nx, ny)); } } var tlen = new int[h][]; for (var i = 0; i < tlen.Length; ++i) tlen[i] = Enumerable.Repeat(int.MaxValue, w).ToArray(); tlen[h - 1][w - 1] = 0; q.Enqueue((h - 1, w - 1)); while (q.Count > 0) { var cur = q.Dequeue(); for (var i = 0; i < mx.Length; ++i) { var nx = cur.x + mx[i]; var ny = cur.y + my[i]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if (map[nx][ny] != '.') continue; if (tlen[nx][ny] <= tlen[cur.x][cur.y] + 1) continue; tlen[nx][ny] = tlen[cur.x][cur.y] + 1; q.Enqueue((nx, ny)); } } for (var i = 0; i < h; ++i) for (var j = 0; j < w; ++j) { if (slen[i][j] >= l - 1 && (slen[i][j] - l + 1) % 2 == 0 && tlen[i][j] >= k - r && (tlen[i][j] - k + r) % 2 == 0 && (vrev[i][j] || hrev[i][j])) { var ans = Reverse(Move(0, 0, i, j, slen)); while (ans.Count + 1 < l) { ans.Add(Rev(ans[ans.Count - 1])); } for (var p = 0; p < r - l + 1; p += 2) { if (vrev[i][j]) { ans.Add('U'); ans.Add('D'); } else { ans.Add('L'); ans.Add('R'); } } ans.AddRange(Move(h - 1, w - 1, i, j, tlen)); while (ans.Count < k) { ans.Add(Rev(ans[ans.Count - 1])); } WriteLine("Yes"); WriteLine(string.Concat(ans)); return; } } WriteLine("No"); } static int[] mx = new int[] { 0, 0, -1, 1 }; static int[] my = new int[] { -1, 1, 0, 0 }; static string mc = "LRUD"; static List<char> Move(int sx, int sy, int tx, int ty, int[][] len) { var cx = tx; var cy = ty; var ans = new List<char>(); while (cx != sx || cy != sy) { for (var i = 0; i < mx.Length; ++i) { var nx = cx + mx[i]; var ny = cy + my[i]; if (nx < 0 || nx >= len.Length || ny < 0 || ny >= len[nx].Length) continue; if (len[nx][ny] < len[cx][cy]) { ans.Add(mc[i]); cx = nx; cy = ny; break; } } } return ans; } static List<char> Reverse(List<char> list) { var ans = list.Select(c => Rev(c)).ToList(); ans.Reverse(); return ans; } static char Rev(char c) { if (c == 'L') return 'R'; if (c == 'R') return 'L'; if (c == 'U') return 'D'; return 'U'; } }