結果

問題 No.707 書道
コンテスト
ユーザー tak
提出日時 2018-07-02 19:18:44
言語 F#
(F# 10.0)
コンパイル:
fsharp_c _filename_
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 846 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,575 ms
コンパイル使用メモリ 212,264 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2026-03-21 17:23:00
合計ジャッジ時間 7,291 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (295 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

let calCost sy sx (map : char[][]) = 
    let cal y x = (sy - y) ** 2.0 + (sx - x) ** 2.0 |> sqrt       
    let mutable cost = 0.0
    for i in 1 .. map |> Array.length do
        for j in 1 .. map.[0] |> Array.length do 
            if map.[i-1].[j-1] = '1' then
                cost <- cost + (cal (i |> float) (j |> float))
    cost                

let H, W = 
    let t = stdin.ReadLine().Split()
            |> Array.map int
    in t.[0], t.[1]
    
let P = Array.init H (fun _ -> stdin.ReadLine().ToCharArray())

let mutable ans = 1 <<< 16 |> float
    
for i in 1 .. H do 
    ans <- min ans (calCost (i |> float) 0.0 P)
    ans <- min ans (calCost (i |> float) (W + 1 |> float) P)

for i in 1 .. W do 
    ans <- min ans (calCost 0.0 (i |> float) P)
    ans <- min ans (calCost (H + 1 |> float) (i |> float)  P)

ans |> printfn "%A"    
0