結果

問題 No.4 おもりと天秤
ユーザー satonakatakumisatonakatakumi
提出日時 2021-08-05 22:41:02
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 2,405 bytes
コンパイル時間 8,132 ms
コンパイル使用メモリ 219,392 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 15:25:10
合計ジャッジ時間 9,298 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

{-# LANGUAGE BangPatterns         #-}
{-# LANGUAGE CPP                  #-}
{-# LANGUAGE DefaultSignatures    #-}
{-# LANGUAGE DerivingStrategies   #-}
{-# LANGUAGE DerivingVia          #-}
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE KindSignatures       #-}
{-# LANGUAGE RecordWildCards      #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# LANGUAGE UndecidableInstances #-}

-- module Yukicoder.No4 where

import           Control.Monad
import           Control.Monad.Cont
import           Control.Monad.Fix
import           Control.Monad.ST
import           Control.Monad.State
import           Data.Bits
import           Data.Bool
import           Data.Char
import           Data.Coerce
import qualified Data.Foldable                     as F
import           Data.Int
import           Data.IORef
import qualified Data.List                         as L
import           Data.Maybe
import           Data.STRef
import           Data.Word
import           GHC.Exts
import           System.CPUTime
import           System.IO
import           Unsafe.Coerce

import qualified Data.ByteString                   as BS
import qualified Data.ByteString.Builder           as BSB
import qualified Data.ByteString.Char8             as BSC8
import qualified Data.ByteString.Unsafe            as BSU

import qualified Data.Vector                       as V
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
import qualified Data.Vector.Generic               as VG
import qualified Data.Vector.Generic.Mutable       as VGM
import qualified Data.Vector.Mutable               as VM
import qualified Data.Vector.Unboxed               as VU
import qualified Data.Vector.Unboxed.Mutable       as VUM

readInts :: Int -> IO (VU.Vector Int)
readInts n = VU.unfoldrN n _f <$> BSC8.getLine
  where
    _f = runStateT (coerce $ BSC8.readInt . BSC8.dropWhile isSpace)

main :: IO ()
main = do
  n <- readLn :: IO Int
  ws <- readInts n
  let s = VU.sum ws
  if odd s
    then putStrLn "impossible"
    else do
      let vec = f ws
      if vec VU.! (s `div` 2)
        then putStrLn "possible"
        else putStrLn "impossible"

f :: VU.Vector Int -> VU.Vector Bool
f ws = VU.create $ do
  dp <- VUM.unsafeNew 100010
  VUM.unsafeWrite dp 0 True
  forM_ [0..10001] $ \i -> do
    VU.forM_ ws $ \w -> do
      dpi <- VUM.unsafeRead dp i
      when (i + w <= 5000 && dpi) $ VUM.unsafeWrite dp (i + w) True
  return dp
0