結果

問題 No.806 木を道に
ユーザー iwotiwot
提出日時 2020-05-20 20:42:25
言語 Haskell
(9.6.2)
結果
AC  
実行時間 793 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 163,568 KB
実行使用メモリ 95,004 KB
最終ジャッジ日時 2023-07-25 05:25:05
合計ジャッジ時間 11,509 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,296 KB
testcase_01 AC 2 ms
7,184 KB
testcase_02 AC 3 ms
7,844 KB
testcase_03 AC 3 ms
7,692 KB
testcase_04 AC 3 ms
7,332 KB
testcase_05 AC 3 ms
8,176 KB
testcase_06 AC 3 ms
7,884 KB
testcase_07 AC 3 ms
7,312 KB
testcase_08 AC 2 ms
7,352 KB
testcase_09 AC 3 ms
7,480 KB
testcase_10 AC 162 ms
28,212 KB
testcase_11 AC 143 ms
25,712 KB
testcase_12 AC 675 ms
75,320 KB
testcase_13 AC 463 ms
63,500 KB
testcase_14 AC 624 ms
73,012 KB
testcase_15 AC 674 ms
76,936 KB
testcase_16 AC 222 ms
35,184 KB
testcase_17 AC 574 ms
69,952 KB
testcase_18 AC 62 ms
16,368 KB
testcase_19 AC 172 ms
29,264 KB
testcase_20 AC 594 ms
69,992 KB
testcase_21 AC 313 ms
42,492 KB
testcase_22 AC 793 ms
94,832 KB
testcase_23 AC 793 ms
95,004 KB
testcase_24 AC 293 ms
51,216 KB
testcase_25 AC 434 ms
69,008 KB
testcase_26 AC 163 ms
31,524 KB
testcase_27 AC 544 ms
82,360 KB
testcase_28 AC 22 ms
12,600 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.Monad
import Data.List
import qualified Data.IntMap.Strict as M

main = do
    n <- (read :: String -> Int) <$> getLine
    s <- replicateM (n-1) ((map read :: [String] -> [Int]) . words <$> getLine)
    print (solve s)

solve :: [[Int]] -> Int
solve xs = foldl (\n v -> (max (v - 2) 0) + n) 0 (counter (concat xs) M.empty)

counter :: [Int] -> M.IntMap Int -> M.IntMap Int
counter [] count = count
counter (x : xs) count = case M.lookup x count of
                            Nothing -> counter xs (M.insert x 1 count)
                            Just n -> counter xs (M.insert x (n+1) count)
0