結果
問題 | No.13 囲みたい! |
ユーザー | vain0 |
提出日時 | 2015-10-23 21:43:55 |
言語 | F# (.NET 7) |
結果 |
AC
|
実行時間 | 95 ms / 5,000 ms |
コード長 | 1,343 bytes |
コンパイル時間 | 3,819 ms |
コンパイル使用メモリ | 167,788 KB |
実行使用メモリ | 26,900 KB |
最終ジャッジ日時 | 2023-08-03 13:57:25 |
合計ジャッジ時間 | 6,187 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
22,964 KB |
testcase_01 | AC | 89 ms
22,988 KB |
testcase_02 | AC | 88 ms
22,860 KB |
testcase_03 | AC | 92 ms
22,504 KB |
testcase_04 | AC | 89 ms
23,060 KB |
testcase_05 | AC | 95 ms
26,372 KB |
testcase_06 | AC | 91 ms
22,984 KB |
testcase_07 | AC | 94 ms
25,152 KB |
testcase_08 | AC | 93 ms
25,008 KB |
testcase_09 | AC | 93 ms
26,900 KB |
testcase_10 | AC | 89 ms
22,924 KB |
testcase_11 | AC | 93 ms
25,000 KB |
testcase_12 | AC | 91 ms
24,972 KB |
testcase_13 | AC | 90 ms
22,848 KB |
testcase_14 | AC | 89 ms
22,928 KB |
testcase_15 | AC | 89 ms
22,928 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved. /home/judge/data/code/Main.fs(11,7): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[|_; _; _|]' may indicate a case not covered by the pattern(s).
ソースコード
open System open System.Text open System.Collections.Generic module Str = let split (delim: string) (s: string) = s.Split ([| delim |], StringSplitOptions.RemoveEmptyEntries) [<EntryPoint>] let main argv = let [| w; h |] = Console.ReadLine () |> Str.split " " |> Array.map (Int32.Parse) let board = [| for i in 0..(h - 1) do let s = Console.ReadLine () yield s |> Str.split " " |> Array.map (Int32.Parse) |] let containsCycle () = let neighbors4 = [(1, 0); (0, 1); (-1, 0); (0, -1)] let visited = Array2D.init h w (fun _ _ -> false) let rec dfs backstep (i0, j0) = if visited.[i0, j0] then true else visited.[i0, j0] <- true Seq.exists id (seq { for (di, dj) in neighbors4 do let (i, j) = (i0 + di, j0 + dj) if 0 <= i && i < h && 0 <= j && j < w && (i, j) <> backstep && board.[i].[j] = board.[fst backstep].[snd backstep] then yield dfs (i0, j0) (i, j) }) Seq.exists id (seq { for i in 0..(h - 1) do for j in 0..(w - 1) do if not visited.[i, j] then yield dfs (i, j) (i, j) }) printfn "%s" <| if containsCycle () then "possible" else "impossible" //exit code 0