結果

問題 No.883 ぬりえ
ユーザー HaarHaar
提出日時 2019-09-15 08:46:00
言語 Haskell
(9.10.1)
結果
RE  
実行時間 -
コード長 642 bytes
コンパイル時間 4,271 ms
コンパイル使用メモリ 177,408 KB
実行使用メモリ 49,888 KB
最終ジャッジ日時 2024-07-06 22:39:38
合計ジャッジ時間 6,151 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 1 RE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:13:9: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
13 |     c = head [x | x<-[0..k], x*x>=b]
   |         ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Array.IO
import Control.Monad

slice n [] = []
slice n xs = take n xs : slice n (drop n xs)

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]

  let
    a = n `div` (k*k)
    b = n `mod` (k*k)
    c = head [x | x<-[0..k], x*x>=b]

    m = a*k+c

  ans <- newArray ((1,1),(m,m)) '.' :: IO (IOArray (Int,Int) Char)

  forM [0..a-1] $ \i -> do
    forM [1..k] $ \x -> do
      forM [1..k] $ \y -> do
        writeArray ans (i*k+x, i*k+y) '#'

  forM [0..b-1] $ \i -> do
    let
      x = a*k + i`mod`k+1
      y = a*k + i`div`k+1
    writeArray ans (x,y) '#'
  
  print m
  mapM_ putStrLn =<< slice m <$> getElems ans


0