Submission #47055587


Source Code Expand

Copy
import qualified Data.IntMap as IM
import Data.List
main :: IO ()
main = do
[n,x,y] <- map read . words <$> getLine
as <- map read . words <$> getLine
let ans = abc326f n x y as
putStrLn ans
abc326f :: Int -> Int -> Int -> [Int] -> String
abc326f n x y as =
case (xans, yans) of
(xans1:_, yans1:_) -> "Yes\n" ++ goEW True yans1 xans1 as
_ -> "No"
where
-- xy
dxs = [ai | (ai,True) <- zip as $ cycle [False,True]]
dys = [ai | (ai,True) <- zip as $ cycle [True,False]]
n4 = max 10 $ div n 4
--
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import qualified Data.IntMap as IM
import Data.List

main :: IO ()
main = do
  [n,x,y] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  let ans = abc326f n x y as
  putStrLn ans

abc326f :: Int -> Int -> Int -> [Int] -> String
abc326f n x y as =
  case (xans, yans) of
    (xans1:_, yans1:_) -> "Yes\n" ++ goEW True yans1 xans1 as
    _ -> "No"
  where
-- x方向とy方向の成分に分離
    dxs = [ai | (ai,True) <- zip as $ cycle [False,True]]
    dys = [ai | (ai,True) <- zip as $ cycle [True,False]]
    n4 = max 10 $ div n 4
-- 前半と後半に分割
    (dxs1,dxs2) = splitAt n4 dxs
    (dys1,dys2) = splitAt n4 dys
-- ±で使ったときの到達地点マップ(base込み)
    [xm1,xm2,ym1,ym2] = map mkSeq [dxs1,dxs2,dys1,dys2]
-- 目標に到達する±の使い方
    xans = findAns (x + sum dxs) xm1 xm2
    yans = findAns (y + sum dys) ym1 ym2

mkSeq :: [Int] -> IM.IntMap [Int]
mkSeq = foldl' step (IM.singleton 0 [])
  where
    step im ai = IM.union imp im
      where
        imp = IM.map (ai :) $ IM.mapKeysMonotonic ((ai + ai) +) im

findAns :: Int -> IM.IntMap [Int] -> IM.IntMap [Int] -> [[Int]]
findAns x xm1 xm2 = [reverse s1 ++ reverse s2 ++ [10^10] | (x1,s1) <- IM.assocs xm1, Just s2 <- [IM.lookup (x - x1) xm2]]

goEW, goNS :: Bool -> [Int] -> [Int] -> [Int] -> String
goEW ew yys@(y:ys) xs (a:as)
  | y == a = (if ew then 'L' else 'R') : goNS True  xs ys  as
  | True   = (if ew then 'R' else 'L') : goNS False xs yys as
goEW _ _ _ [] = []
goNS ns xxs@(x:xs) ys (a:as)
  | x == a = (if ns then 'R' else 'L') : goEW True  ys xs  as
  | True   = (if ns then 'L' else 'R') : goEW False ys xxs as
goNS _ _ _ [] = []

Submission Info

Submission Time
Task F - Robot Rotation
User joetheshootingst
Language Haskell (GHC 9.4.5)
Score 525
Code Size 1722 Byte
Status AC
Exec Time 2783 ms
Memory 457352 KB

Compile Error

app/Main.hs:25:5: warning: [-Wincomplete-uni-patterns]
    Pattern match(es) are non-exhaustive
    In a pattern binding:
        Patterns of type ‘[IM.IntMap [Int]]’ not matched:
            []
            [_]
            [_, _]
            [_, _, _]
            ...
   |
25 |     [xm1,xm2,ym1,ym2] = map mkSeq [dxs1,dxs2,dys1,dys2]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

app/Main.hs:38:53: warning: [-Wtype-defaults]
    • Defaulting the type variable ‘b0’ to type ‘Integer’ in the following constraints
        (Integral b0) arising from a use of ‘^’ at app/Main.hs:38:53
        (Num b0) arising from the literal ‘10’ at app/Main.hs:38:54-55
    • In the expression: 10 ^ 10
      In the second argument of ‘(++)’, namely ‘[10 ^ 10]’
      In the second argument of ‘(++)’, namely ‘reverse s2 ++ [10 ^ 10]’
   |
38 | findAns x xm1 xm2 = [reverse s1 ++ reverse s2 ++ [10^10] | (x1,s1) <- IM.assocs xm1, Just s2 <- [IM.lookup (x - x1) xm2]]
   |                                                     ^

app/Main.hs:41:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘goEW’:
        Patterns of type ‘Bool’, ‘[Int]’, ‘[Int]’, ‘[Int]’ not matched:
            _ [] _ (_:_)
   |
41 | goEW ew yys@(y:ys) xs (a:as)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

app/Main.hs:45:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘goNS’:
        Patterns of type ‘Bool’, ‘[Int]’, ‘[Int]’, ‘[Int]’ not matched:
            _ [] _ (_:_)
   |
45 | goNS ns xxs@(x:xs) ys (a:as)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 4
AC × 48
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
random_01.txt AC 2723 ms 446144 KB
random_02.txt AC 2763 ms 450312 KB
random_03.txt AC 2783 ms 453376 KB
random_04.txt AC 2733 ms 448284 KB
random_05.txt AC 2 ms 7968 KB
random_06.txt AC 2 ms 7824 KB
random_07.txt AC 865 ms 151292 KB
random_08.txt AC 3 ms 9188 KB
random_09.txt AC 1 ms 7248 KB
random_10.txt AC 2 ms 7188 KB
random_11.txt AC 31 ms 19204 KB
random_12.txt AC 2 ms 8392 KB
random_13.txt AC 2743 ms 456388 KB
random_14.txt AC 232 ms 61088 KB
random_15.txt AC 1 ms 6992 KB
random_16.txt AC 1650 ms 340680 KB
random_17.txt AC 91 ms 29120 KB
random_18.txt AC 2 ms 7984 KB
random_19.txt AC 2 ms 8064 KB
random_20.txt AC 3 ms 9204 KB
random_21.txt AC 2673 ms 444100 KB
random_22.txt AC 1523 ms 449148 KB
random_23.txt AC 1543 ms 446216 KB
random_24.txt AC 2702 ms 443896 KB
random_25.txt AC 1 ms 7148 KB
random_26.txt AC 1228 ms 260864 KB
random_27.txt AC 1 ms 7000 KB
random_28.txt AC 1 ms 7052 KB
random_29.txt AC 1 ms 7064 KB
random_30.txt AC 2 ms 7780 KB
random_31.txt AC 2 ms 7512 KB
random_32.txt AC 4 ms 10156 KB
random_33.txt AC 1532 ms 446212 KB
random_34.txt AC 61 ms 28288 KB
random_35.txt AC 1583 ms 457352 KB
random_36.txt AC 21 ms 14736 KB
random_37.txt AC 2 ms 7648 KB
random_38.txt AC 2 ms 7516 KB
random_39.txt AC 2 ms 7860 KB
random_40.txt AC 2 ms 7512 KB
random_41.txt AC 1 ms 6864 KB
random_42.txt AC 1 ms 6924 KB
random_43.txt AC 1 ms 6912 KB
random_44.txt AC 1 ms 7012 KB
sample_01.txt AC 1 ms 7128 KB
sample_02.txt AC 1 ms 6952 KB
sample_03.txt AC 1 ms 6948 KB
sample_04.txt AC 1 ms 7240 KB


2025-04-24 (Thu)
14:10:36 +00:00