結果

問題 No.694 square1001 and Permutation 3
ユーザー konsin_tokagekonsin_tokage
提出日時 2018-06-24 09:28:55
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 553 bytes
コンパイル時間 11,206 ms
コンパイル使用メモリ 165,304 KB
実行使用メモリ 813,504 KB
最終ジャッジ日時 2023-09-13 13:29:04
合計ジャッジ時間 17,541 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,392 KB
testcase_01 AC 3 ms
7,420 KB
testcase_02 AC 3 ms
7,404 KB
testcase_03 AC 7 ms
10,944 KB
testcase_04 AC 7 ms
11,228 KB
testcase_05 AC 12 ms
11,928 KB
testcase_06 AC 12 ms
11,888 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Monad
import qualified Data.Set as S
indexB x s = S.findIndex (x,0) s
indexE x s = S.findIndex e s
  where Just e = S.lookupLE (x, maxBound :: Int) s
count x s = indexE x s - indexB x s + 1
insert x s
  | S.member (x,0) s = S.insert (x, count x s) s
  | otherwise = S.insert (x,0) s
solve n a = take n $ scanl step r a
  where 
    ss@(s:_) = scanr insert S.empty a
    r = sum $ zipWith indexB a ss
    step r x = r + n - count x s - indexB x s * 2
main = do
  n <- readLn
  a <- replicateM n readLn :: IO [Int]
  mapM_ print $ solve n a
0