Submission #17658275
Source Code Expand
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DatatypeContexts #-}
import Control.Exception (assert)
import Control.Monad
import Control.Monad.Primitive
import qualified Control.Monad.ST as ST
import qualified Data.Array.IO as IO
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as A
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Foldable
import Data.List
import qualified Data.Map.Strict as Map
import Data.Maybe
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import qualified Data.Vector as VB
import qualified Data.Vector.Mutable as VBM
import qualified Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Base
import qualified Data.Vector.Unboxed.Mutable as VM
import Debug.Trace
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine
inf :: Int
inf = 10^18
quickSortVec l u arr
| l >= u = return ()
| otherwise = do
VM.unsafeSwap arr l ((u+l)`div`2)
t <- VM.unsafeRead arr l
let i = l
j = u + 1
nj <- loopVec t u i j arr
VM.unsafeSwap arr l nj
quickSortVec l (nj-1) arr
quickSortVec (nj+1) u arr
loopVec !t !u !i !j arr = do
ni <- doWhile i (+1) (< t)
nj <- doWhile j (subtract 1) (> t)
if ni > nj
then return nj
else do VM.unsafeSwap arr ni nj
loopVec t u ni nj arr
where
{-# INLINE doWhile #-}
doWhile k op p
| nk > u = return nk
| otherwise = do
x <- VM.unsafeRead arr nk
if p x then
doWhile nk op p
else
return nk
where
nk = op k
main = do
[n, k] <- getIntList
wps <- replicateM n $ do [w, p] <- getIntList
return (w, p)
let (ws', ps') = unzip wps
ws = V.fromList ws'
ps = V.fromList ps'
v <- VM.new n
VM.set v (0::Double)
let test :: Double -> IO Double
test x = do forM_ [0..(n-1)] $ \i -> do
let w = fromIntegral (ws V.! i) :: Double
p = fromIntegral (ps V.! i) :: Double
d = (p-x) * w
VM.write v i d
quickSortVec 0 n v
sumK 0 0.0
sumK :: Int -> Double -> IO Double
sumK i r
| i < k = do t <- VM.read v (n-1-i)
sumK (i+1) (r+t)
| otherwise = return r
solve :: Int -> Double -> Double -> IO Double
solve i l r
| i > 1000 || l >= r = return l
| otherwise = do let m = (l + r) / 2.0
x <- test m
if abs x < 1e-6
then return m
else if x < 0
then solve (i+1) l m
else solve (i+1) m r
ans <- solve 0 0.0 100.0
print ans
Submission Info
| Submission Time | |
|---|---|
| Task | D - 食塩水 |
| User | unnohideyuki |
| Language | Haskell (GHC 8.8.3) |
| Score | 100 |
| Code Size | 3707 Byte |
| Status | AC |
| Exec Time | 132 ms |
| Memory | 5592 KiB |
Compile Error
Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default
Main.hs:2:14: warning:
-XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language.
|
2 | {-# LANGUAGE DatatypeContexts #-}
| ^^^^^^^^^^^^^^^^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s0.txt, s1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, s0.txt, s1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 128 ms | 5592 KiB |
| 001.txt | AC | 5 ms | 5188 KiB |
| 002.txt | AC | 125 ms | 5536 KiB |
| 003.txt | AC | 9 ms | 5288 KiB |
| 004.txt | AC | 130 ms | 5552 KiB |
| 005.txt | AC | 123 ms | 5592 KiB |
| 006.txt | AC | 120 ms | 5500 KiB |
| 007.txt | AC | 110 ms | 5312 KiB |
| 008.txt | AC | 126 ms | 5340 KiB |
| 009.txt | AC | 5 ms | 5184 KiB |
| 010.txt | AC | 125 ms | 5488 KiB |
| 011.txt | AC | 57 ms | 5196 KiB |
| 012.txt | AC | 132 ms | 5340 KiB |
| 013.txt | AC | 57 ms | 5200 KiB |
| 014.txt | AC | 127 ms | 5488 KiB |
| 015.txt | AC | 99 ms | 5364 KiB |
| 016.txt | AC | 127 ms | 5404 KiB |
| 017.txt | AC | 80 ms | 5408 KiB |
| 018.txt | AC | 124 ms | 5484 KiB |
| 019.txt | AC | 89 ms | 5440 KiB |
| s0.txt | AC | 2 ms | 4180 KiB |
| s1.txt | AC | 2 ms | 4176 KiB |