提出 #19412335


ソースコード 拡げる

{-# 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

main = do
    [n, m, k] <- getIntList

    let p = 998244353
        r0 = m * modpow (m-1) (n-1) p `mod` p
        c0 = 1

        solve i c res
          | i > k = res
          | otherwise = let r' = m * modpow (m-1) (n-1-i) p `mod` p
                            c' = c * (n-i) `mod` p * modinv i p `mod` p
                            res' = (r' * c' `mod` p + res) `mod` p
                        in solve (i+1) c' res'

    print $ solve 1 c0 (r0 * c0 `mod` p)

-- compulte a^n `mod` p
modpow :: Int -> Int -> Int -> Int
modpow a n p =
  let modpow' :: Integer -> Integer -> Integer -> Integer
      modpow' a n res | n == 0    = res
                      | otherwise =
                          modpow' (a*a`mod`p')
                                  (n `shiftR` 1)
                                  (if (n .&. 1) == 1 then res * a `mod` p' else res)
      p' = fromIntegral p
  in fromInteger $ modpow' (fromIntegral a) (fromIntegral n) 1

-- compute a^(-1) `mod` p
modinv :: Int -> Int -> Int
modinv a p = modpow a (p-2) p

提出情報

提出日時
問題 E - Colorful Blocks
ユーザ unnohideyuki
言語 Haskell (GHC 8.8.3)
得点 500
コード長 2514 Byte
結果 AC
実行時間 849 ms
メモリ 4852 KiB

コンパイルエラー

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Main.hs:1:14: warning:
    -XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language.
  |
1 | {-# LANGUAGE DatatypeContexts #-}
  |              ^^^^^^^^^^^^^^^^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 43
セット名 テストケース
Sample 00-Sample-00, 00-Sample-01, 00-Sample-02
All 00-Sample-00, 00-Sample-01, 00-Sample-02, 01-Handmade-00, 01-Handmade-01, 01-Handmade-02, 01-Handmade-03, 01-Handmade-04, 01-Handmade-05, 01-Handmade-06, 01-Handmade-07, 01-Handmade-08, 01-Handmade-09, 02-Random-00, 02-Random-01, 02-Random-02, 02-Random-03, 02-Random-04, 02-Random-05, 02-Random-06, 02-Random-07, 02-Random-08, 02-Random-09, 02-Random-10, 02-Random-11, 02-Random-12, 02-Random-13, 02-Random-14, 02-Random-15, 02-Random-16, 02-Random-17, 02-Random-18, 02-Random-19, 02-Random-20, 02-Random-21, 02-Random-22, 02-Random-23, 02-Random-24, 02-Random-25, 02-Random-26, 02-Random-27, 02-Random-28, 02-Random-29
ケース名 結果 実行時間 メモリ
00-Sample-00 AC 17 ms 3604 KiB
00-Sample-01 AC 2 ms 3712 KiB
00-Sample-02 AC 44 ms 4740 KiB
01-Handmade-00 AC 2 ms 3644 KiB
01-Handmade-01 AC 2 ms 3660 KiB
01-Handmade-02 AC 2 ms 3648 KiB
01-Handmade-03 AC 2 ms 3712 KiB
01-Handmade-04 AC 2 ms 3636 KiB
01-Handmade-05 AC 748 ms 4596 KiB
01-Handmade-06 AC 2 ms 3528 KiB
01-Handmade-07 AC 849 ms 4780 KiB
01-Handmade-08 AC 321 ms 4720 KiB
01-Handmade-09 AC 8 ms 4664 KiB
02-Random-00 AC 10 ms 4684 KiB
02-Random-01 AC 15 ms 4720 KiB
02-Random-02 AC 11 ms 4712 KiB
02-Random-03 AC 4 ms 4564 KiB
02-Random-04 AC 10 ms 4712 KiB
02-Random-05 AC 2 ms 3712 KiB
02-Random-06 AC 3 ms 3928 KiB
02-Random-07 AC 10 ms 4700 KiB
02-Random-08 AC 2 ms 3856 KiB
02-Random-09 AC 5 ms 4540 KiB
02-Random-10 AC 9 ms 4688 KiB
02-Random-11 AC 16 ms 4600 KiB
02-Random-12 AC 14 ms 4700 KiB
02-Random-13 AC 8 ms 4696 KiB
02-Random-14 AC 5 ms 4536 KiB
02-Random-15 AC 9 ms 4508 KiB
02-Random-16 AC 98 ms 4780 KiB
02-Random-17 AC 272 ms 4712 KiB
02-Random-18 AC 340 ms 4600 KiB
02-Random-19 AC 591 ms 4732 KiB
02-Random-20 AC 219 ms 4720 KiB
02-Random-21 AC 19 ms 4724 KiB
02-Random-22 AC 558 ms 4788 KiB
02-Random-23 AC 531 ms 4596 KiB
02-Random-24 AC 70 ms 4728 KiB
02-Random-25 AC 415 ms 4596 KiB
02-Random-26 AC 40 ms 4708 KiB
02-Random-27 AC 580 ms 4852 KiB
02-Random-28 AC 198 ms 4724 KiB
02-Random-29 AC 44 ms 4604 KiB