Submission #54662401
Source Code Expand
import Data.Array
import Data.List
import Data.List.Split
main :: IO ()
main = do
[n,m,k] <- getLnInts
let ans = abc358f n m k
putStrLn ans
getLnInts :: IO [Int]
getLnInts = map read . words <$> getLine
abc358f :: Int -> Int -> Int -> String
abc358f n m k =
case mkRoute of
Nothing -> "No"
Just (_:ds) -> unlines $ ("Yes" :) $ enStr $ mkMaze ds
where
mkRoute
| k < n = Nothing -- 届かないパターン
| odd n /= odd k = Nothing -- 偶奇が異なるパターン
| odd n, even m, k >= n * m = Nothing -- 1マス埋められないパターン
| odd n, k <= 1 + pred n * m = Just $ 'd' : doEven (pred n) (pred k) -- 偶数と同じで済むパターン
| odd n = Just $ 'b' : doOdd -- 奇数で面倒なパターン
| otherwise = Just $ doEven n k -- 偶数のパターン
doEven 0 0 = ""
doEven n1 k1 = 'D' : replicate w 'L' ++ 'D' : replicate w 'R' ++ doEven (n1 - 2) (k1 - 2 * succ w)
where
w = min (pred m) $ div (k1 - n1) 2
doOdd = 'D' : loop (k - 3 - (n-3) * m) (doEven (n-3) ((n-3) * m))
loop x rest
| x >= 6 = "LULD" ++ loop (x - 6) ("RR" ++ rest)
| x == 4 = "LLDRR" ++ rest
| x == 2 = "LDR" ++ rest
| x == 0 = 'D' : rest
enStr arr = chunksOf (m + succ m) $ elems arr
mkMaze ds = accumArray (flip const) '+' ((-1,-1),(n + pred n, m + pred m)) $
((-1, 2 * pred m), 'S') : ((n + pred n, 2 * pred m), 'G') :
[((i,j),'o') | i <- [0, 2 .. 2 * pred n], j <- [0, 2 .. 2 * pred m]] ++
[((i,j),'|') | i <- [0, 2 .. 2 * pred n], j <- [1, 3 .. 2 * pred m]] ++
[((i,j),'-') | i <- [1, 3 .. 2 * pred n], j <- [0, 2 .. 2 * pred m]] ++
[( ij ,'.') | ij <- decode ds]
decode ds = snd $ mapAccumL step (0, 2 * pred m) ds
where
step (i,j) 'D' = ((i+2,j),(i+1,j))
step (i,j) 'U' = ((i-2,j),(i-1,j))
step (i,j) 'L' = ((i,j-2),(i,j-1))
step (i,j) 'R' = ((i,j+2),(i,j+1))
Submission Info
Submission Time
2024-06-17 16:11:08+0900
Task
F - Easiest Maze
User
joetheshootingst
Language
Haskell (GHC 9.4.5)
Score
525
Code Size
2058 Byte
Status
AC
Exec Time
5 ms
Memory
11188 KiB
Compile Error
app/Main.hs:16:3: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative:
Patterns of type ‘Maybe [Char]’ not matched: Just []
|
16 | case mkRoute of
| ^^^^^^^^^^^^^^^...
app/Main.hs:32:5: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘loop’:
Patterns of type ‘a’, ‘[Char]’ not matched: _ _
|
32 | loop x rest
| ^^^^^^^^^^^...
app/Main.hs:46:9: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘step’:
Patterns of type ‘(a, b)’, ‘Char’ not matched:
(_, _) p where p is not one of {'R', 'L', 'D', ...}
|
46 | step (i,j) 'D' = ((i+2,j),(i+1,j))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
525 / 525
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 02_handmade_00.txt, 02_handmade_01.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
6648 KiB
00_sample_01.txt
AC
1 ms
6596 KiB
00_sample_02.txt
AC
1 ms
6740 KiB
01_random_00.txt
AC
1 ms
6624 KiB
01_random_01.txt
AC
4 ms
10984 KiB
01_random_02.txt
AC
1 ms
6460 KiB
01_random_03.txt
AC
1 ms
6692 KiB
01_random_04.txt
AC
1 ms
7276 KiB
01_random_05.txt
AC
1 ms
6596 KiB
01_random_06.txt
AC
1 ms
6644 KiB
01_random_07.txt
AC
1 ms
6628 KiB
01_random_08.txt
AC
1 ms
6940 KiB
01_random_09.txt
AC
1 ms
7008 KiB
01_random_10.txt
AC
1 ms
6456 KiB
01_random_11.txt
AC
1 ms
6728 KiB
01_random_12.txt
AC
1 ms
7128 KiB
01_random_13.txt
AC
1 ms
6668 KiB
01_random_14.txt
AC
1 ms
7004 KiB
01_random_15.txt
AC
1 ms
6676 KiB
01_random_16.txt
AC
1 ms
7108 KiB
01_random_17.txt
AC
1 ms
6656 KiB
01_random_18.txt
AC
1 ms
7108 KiB
01_random_19.txt
AC
1 ms
6588 KiB
01_random_20.txt
AC
1 ms
6664 KiB
01_random_21.txt
AC
1 ms
6996 KiB
01_random_22.txt
AC
1 ms
6692 KiB
01_random_23.txt
AC
4 ms
11124 KiB
01_random_24.txt
AC
1 ms
6676 KiB
01_random_25.txt
AC
5 ms
11156 KiB
01_random_26.txt
AC
1 ms
6632 KiB
01_random_27.txt
AC
5 ms
11068 KiB
01_random_28.txt
AC
1 ms
6728 KiB
01_random_29.txt
AC
4 ms
10952 KiB
01_random_30.txt
AC
4 ms
11108 KiB
01_random_31.txt
AC
1 ms
6680 KiB
01_random_32.txt
AC
4 ms
11096 KiB
01_random_33.txt
AC
1 ms
6700 KiB
01_random_34.txt
AC
1 ms
6664 KiB
01_random_35.txt
AC
1 ms
6584 KiB
01_random_36.txt
AC
1 ms
6960 KiB
01_random_37.txt
AC
1 ms
6704 KiB
01_random_38.txt
AC
4 ms
11156 KiB
01_random_39.txt
AC
4 ms
11080 KiB
01_random_40.txt
AC
1 ms
6500 KiB
01_random_41.txt
AC
1 ms
6688 KiB
01_random_42.txt
AC
5 ms
11160 KiB
01_random_43.txt
AC
1 ms
6720 KiB
01_random_44.txt
AC
4 ms
11188 KiB
01_random_45.txt
AC
4 ms
11120 KiB
01_random_46.txt
AC
1 ms
6696 KiB
01_random_47.txt
AC
1 ms
6692 KiB
01_random_48.txt
AC
5 ms
11160 KiB
02_handmade_00.txt
AC
5 ms
11156 KiB
02_handmade_01.txt
AC
4 ms
10940 KiB