結果

問題 No.239 にゃんぱすー
ユーザー ichibanshiboriichibanshibori
提出日時 2016-10-25 11:58:04
言語 OCaml
(5.1.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,078 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 19,712 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 08:35:08
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 4 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 3 ms
6,940 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 3 ms
6,940 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

type greeting = NYANPASS | OTHER | NA

let greeting_of_string =
  function | "nyanpass" -> NYANPASS | "-" -> NA | _ -> OTHER

let array_forall f arr = Array.to_list arr |> List.for_all f

let solve n arr =
  let rec solve' j result =
    if j >= n || (List.length result) > 1 then result
    else
      let isRentyon =
        array_forall (fun g -> g = NYANPASS || g = NA) arr.(j)
      in
      let nextResult = if isRentyon then j::result else result
      in
      solve' (j + 1) nextResult
  in
  let result = solve' 0 [] in
  match result with
  | j::[] -> j + 1
  | _ -> -1

let read_matrix n =
  let arr = Array.make_matrix n n NA
  in
  let rec read_matrix' i =
    if (i < n) then (
      let glst = read_line () |>
                 Str.split (Str.regexp_string " ") |>
                 List.map greeting_of_string
      in
      List.iteri (fun j g -> arr.(j).(i) <- g) glst;
      read_matrix' (i + 1)
    )
  in
  read_matrix' 0;
  arr

let () =
  let n = read_line () |> int_of_string in
  let arr = read_matrix n in
  solve n arr |> string_of_int |> print_endline
0