Submission #68145218


Source Code Expand

{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# HLINT ignore "Use lambda-case" #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# HLINT ignore "Used otherwise as a pattern" #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}

module Main where

import Control.Applicative ((<|>))
import Control.Monad
import Control.Monad.ST
import Control.Monad.State (MonadState (get), StateT (StateT, runStateT))
import Data.Array (Array)
import Data.Array.IArray
import Data.Array.IO
import Data.Array.IO.Internals (IOArray (IOArray), IOUArray (IOUArray))
import Data.Array.MArray
import Data.Array.ST ()
import Data.Array.ST.Safe (runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.Bifoldable (Bifoldable (bifold))
import Data.Bifunctor (bimap)
import Data.Bits (xor)
import Data.Bool (bool)
import Data.ByteString.Char8 qualified as BC
import Data.Char (digitToInt, ord)
import Data.Char qualified as C
import Data.Foldable (for_)
import Data.Foldable.Extra (traverse_)
import Data.Function (fix, on)
import Data.Graph.Inductive (deg', neighbors')
import Data.HashSet qualified as HS
import Data.Heap qualified as H
import Data.IORef (modifyIORef', newIORef, readIORef, writeIORef)
import Data.IORef qualified as MV
import Data.IntMap qualified as IM
import Data.IntSet qualified as IS
import Data.Ix
import Data.List
import Data.List.Extra
import Data.Map qualified as M
import Data.Maybe
import Data.Mutable
import Data.Ord
import Data.Ratio ((%))
import Data.STRef (modifySTRef', newSTRef, readSTRef, writeSTRef)
import Data.Sequence (Seq (Empty, (:<|), (:|>)), ViewL ((:<)), ViewR ((:>)), (|>))
import Data.Sequence qualified as Seq
import Data.Set qualified as S
import Data.Vector qualified as V
import Data.Vector.Generic qualified as VG
import Data.Vector.Unboxed qualified as VU
import Data.Vector.Unboxed.Mutable qualified as MV
import Debug.Trace (traceShow)
import GHC.IO (unsafePerformIO)
import System.Environment (lookupEnv)

main :: IO ()
main = do
  [n, m] <- getInts
  as <- getInts
  bs <- getInts

  let im = foldl' (\acc a -> IM.insertWith (+) a 1 acc) IM.empty as
      im' = foldl' (flip (IM.adjust (\v -> v - 1))) im bs
      ans = concat [replicate v k | let lst = IM.toAscList im', (k, v) <- lst, v > 0]

  printList ans

{-- lib --}
-- inputs
getInts :: IO [Int]
getInts = unfoldr (BC.readInt . BC.dropWhile C.isSpace) <$> BC.getLine

getInteger :: IO [Integer]
getInteger = unfoldr (BC.readInteger . BC.dropWhile C.isSpace) <$> BC.getLine

-- outputs
printYn :: Bool -> IO ()
printYn f = putStrLn $ bool "No" "Yes" f

printList :: (Show a) => [a] -> IO ()
printList lst = putStrLn $ unwords $ map show lst

-- list
fromListToTuple :: [Int] -> (Int, Int)
fromListToTuple [a, b] = (a, b)

countBy :: (Foldable t) => (e -> Bool) -> t e -> Int
countBy predicate = foldl' (\acc a -> if predicate a then acc + 1 else acc) 0

-- fold
foldFor' :: (Foldable t) => b -> t a -> (b -> a -> b) -> b
foldFor' initial xs f = foldl' f initial xs

foldForM :: (Foldable t, Monad m) => b -> t a -> (b -> a -> m b) -> m b
foldForM initial xs m = foldM m initial xs

foldForM_ :: (Foldable t, Monad m) => b -> t a -> (b -> a -> m b) -> m ()
foldForM_ initial xs m = foldM_ m initial xs

-- Array用のfind
findArrayIndices :: (IArray a e, Ix i) => (e -> Bool) -> a i e -> [i]
findArrayIndices predicate as = [i | (i, e) <- assocs as, predicate e]

-- Array用の(!?)
(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e
(!?) arr i =
  let b = bounds arr
   in if inRange b i
        then Just (arr ! i)
        else Nothing

instance (Num a, Num b) => Num (a, b) where
  (+) :: (Num a, Num b) => (a, b) -> (a, b) -> (a, b)
  (a1, b1) + (a2, b2) = (a1 + a2, b1 + b2)
  (*) :: (Num a, Num b) => (a, b) -> (a, b) -> (a, b)
  (a1, b1) * (a2, b2) = (a1 * a2, b1 * b2)
  abs :: (Num a, Num b) => (a, b) -> (a, b)
  abs (a1, b1) = (abs a1, abs b1)
  signum :: (Num a, Num b) => (a, b) -> (a, b)
  signum (a1, b1) = (signum a1, signum b1)
  fromInteger :: (Num a, Num b) => Integer -> (a, b)
  fromInteger i = (fromInteger i, fromInteger i)
  negate :: (Num a, Num b) => (a, b) -> (a, b)
  negate (a1, b1) = (negate a1, negate b1)

{-- debug --}

dbg :: (Show a) => a -> ()
dbg _ = ()

fnDbg :: (Show a) => a -> a
fnDbg x = x

Submission Info

Submission Time
Task B - Search and Delete
User flowert
Language Haskell (GHC 9.4.5)
Score 200
Code Size 4711 Byte
Status AC
Exec Time 2 ms
Memory 7216 KiB

Compile Error

app/Main.hs:71:4: warning: [-Wunused-matches]
    Defined but not used: ‘n’
   |
71 |   [n, m] <- getInts
   |    ^

app/Main.hs:71:7: warning: [-Wunused-matches]
    Defined but not used: ‘m’
   |
71 |   [n, m] <- getInts
   |       ^

app/Main.hs:98:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘fromListToTuple’:
        Patterns of type ‘[Int]’ not matched:
            []
            [_]
            (_:_:_:_)
   |
98 | fromListToTuple [a, b] = (a, b)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

app/Main.hs:125:1: warning: [-Worphans]
    Orphan instance: instance (Num a, Num b) => Num (a, b)
    Suggested fix:
      Move the instance declaration to the module of the class or of the type, or
      wrap the type with a newtype and declare the instance on the new type.
    |
125 | instance (Num a, Num b) => Num (a, b) where
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 28
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 2 ms 7016 KiB
example_01.txt AC 2 ms 6988 KiB
hand_00.txt AC 2 ms 7064 KiB
hand_01.txt AC 2 ms 6988 KiB
hand_02.txt AC 2 ms 7104 KiB
hand_03.txt AC 2 ms 7060 KiB
hand_04.txt AC 2 ms 6992 KiB
hand_05.txt AC 2 ms 6980 KiB
random_00.txt AC 2 ms 7128 KiB
random_01.txt AC 2 ms 7048 KiB
random_02.txt AC 2 ms 7212 KiB
random_03.txt AC 2 ms 7100 KiB
random_04.txt AC 2 ms 7200 KiB
random_05.txt AC 2 ms 7080 KiB
random_06.txt AC 2 ms 6944 KiB
random_07.txt AC 2 ms 7076 KiB
random_08.txt AC 2 ms 7188 KiB
random_09.txt AC 2 ms 7092 KiB
random_10.txt AC 2 ms 7164 KiB
random_11.txt AC 2 ms 7040 KiB
random_12.txt AC 2 ms 7120 KiB
random_13.txt AC 2 ms 7148 KiB
random_14.txt AC 2 ms 7064 KiB
random_15.txt AC 2 ms 7080 KiB
random_16.txt AC 2 ms 6960 KiB
random_17.txt AC 2 ms 7076 KiB
random_18.txt AC 2 ms 7216 KiB
random_19.txt AC 2 ms 7096 KiB