結果

問題 No.4 おもりと天秤
ユーザー satonakatakumisatonakatakumi
提出日時 2021-08-05 22:52:27
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 2,421 bytes
コンパイル時間 2,657 ms
コンパイル使用メモリ 221,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-16 15:25:27
合計ジャッジ時間 3,406 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 s
      if vec VU.! (s `div` 2)
        then putStrLn "possible"
        else putStrLn "impossible"

f :: VU.Vector Int -> Int -> VU.Vector Bool
f ws s = VU.create $ do
  dp <- VUM.unsafeNew 11111
  VUM.unsafeWrite dp 0 True
  VU.forM_ ws $ \wi -> do
    forM_ [s `div` 2 .. 0] $ \j -> do
      dpj <- VUM.unsafeRead dp j
      when (j + wi <= s && dpj) $ VUM.unsafeWrite dp (j + wi) True
  return dp
0