結果

問題 No.883 ぬりえ
コンテスト
ユーザー Haar
提出日時 2019-09-15 08:48:43
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 642 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,106 ms
コンパイル使用メモリ 192,384 KB
実行使用メモリ 60,800 KB
最終ジャッジ日時 2026-03-28 12:42:32
合計ジャッジ時間 2,335 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/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.Internal.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' 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 #
raw source code

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`c+1
      y = a*k + i`div`c+1
    writeArray ans (x,y) '#'
  
  print m
  mapM_ putStrLn =<< slice m <$> getElems ans


0