結果

問題 No.451 575
ユーザー okadukiokaduki
提出日時 2016-12-07 00:36:17
言語 Haskell
(9.8.2)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 9,662 ms
コンパイル使用メモリ 161,236 KB
実行使用メモリ 76,540 KB
最終ジャッジ日時 2023-08-22 13:48:57
合計ジャッジ時間 15,971 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,156 KB
testcase_01 AC 3 ms
7,236 KB
testcase_02 AC 2 ms
7,164 KB
testcase_03 AC 3 ms
7,228 KB
testcase_04 AC 2 ms
7,172 KB
testcase_05 AC 12 ms
12,884 KB
testcase_06 AC 42 ms
20,768 KB
testcase_07 AC 304 ms
76,540 KB
testcase_08 AC 3 ms
7,288 KB
testcase_09 AC 7 ms
10,508 KB
testcase_10 AC 93 ms
24,624 KB
testcase_11 AC 263 ms
60,924 KB
testcase_12 AC 375 ms
76,424 KB
testcase_13 AC 365 ms
76,416 KB
testcase_14 AC 3 ms
7,620 KB
testcase_15 AC 12 ms
12,400 KB
testcase_16 AC 42 ms
19,808 KB
testcase_17 AC 295 ms
76,324 KB
testcase_18 AC 295 ms
76,352 KB
testcase_19 AC 173 ms
54,640 KB
testcase_20 AC 22 ms
12,688 KB
testcase_21 AC 7 ms
11,412 KB
testcase_22 AC 2 ms
7,364 KB
testcase_23 AC 365 ms
76,260 KB
testcase_24 AC 193 ms
46,664 KB
testcase_25 AC 2 ms
7,396 KB
testcase_26 AC 3 ms
7,352 KB
testcase_27 AC 3 ms
8,288 KB
testcase_28 AC 5 ms
9,652 KB
testcase_29 AC 32 ms
16,352 KB
testcase_30 AC 295 ms
76,328 KB
testcase_31 AC 2 ms
7,208 KB
testcase_32 AC 73 ms
30,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

readInts :: B.ByteString -> [Integer]
readInts = map (fst . fromJust . B.readInteger) . B.words

getInteger :: IO [Integer]
getInteger = liftM readInts B.getLine

solve _ [] _ r = r
solve i (x:xs) acc (l,r) = solve (i+1) xs acc' (l',r')
  where
    acc' = acc + (if (i+1) `mod` 4 < 2 then x else -x)
    (l',r') = if i `mod` 4 < 2
              then (l,min r acc')
              else (max l acc',r)
iter p = scanl (\(prv,f) x -> if f then (x-prv,False) else (prv-x,True)) (p,True)

main = do
  [n] <- getInteger
  bs <- forM [1..n] $ \_ -> head <$> getInteger
  let (l,r) = solve 0 bs 0 (-1,2000000000000000000)
  if l+1 < r && 1 < r
    then print (n+1) >> forM_ (iter (r-1) bs) (print . fst)
    else print (-1)
0