結果

問題 No.840 ほむほむほむら
ユーザー pekempeypekempey
提出日時 2019-06-24 00:28:14
言語 OCaml
(5.1.0)
結果
AC  
実行時間 461 ms / 4,000 ms
コード長 1,220 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 20,352 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:48:11
合計ジャッジ時間 3,567 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 11 ms
5,376 KB
testcase_03 AC 68 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 115 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 33 ms
5,376 KB
testcase_13 AC 303 ms
5,376 KB
testcase_14 AC 41 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 73 ms
5,376 KB
testcase_18 AC 393 ms
5,376 KB
testcase_19 AC 461 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 431 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 10 ms
5,376 KB
testcase_27 AC 437 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
File "Main.ml", line 1, characters 4-10:
1 | let [n; m] = read_line () |> String.split_on_char ' ' |> List.map int_of_string;;
        ^^^^^^
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
n::m::_::_

ソースコード

diff #

let [n; m] = read_line () |> String.split_on_char ' ' |> List.map int_of_string;;

let s = m * m * m;;
let md = 998244353;;

let prod a b = begin
  let c = Array.make (s*s) 0 in
  for i = 0 to s - 1 do
    for k = 0 to s - 1 do
      for j = 0 to s - 1 do
        c.(i*s+j) <- (c.(i*s+j) + a.(i*s+k) * b.(k*s+j)) mod md
      done
    done
  done;
  c
end;;

let power a k = begin
  let res = ref (Array.make (s*s) 0) in
  for i = 0 to s - 1 do
    !res.(i*s+i) <- 1
  done;
  let a = ref a in
  let k = ref k in
  while !k > 0 do
    if !k mod 2 = 1 then
      res := prod !res !a;
    a := prod !a !a;
    k := !k / 2;
  done;
  !res
end;;

let a = Array.make (s*s) 0;;
let f i j k = let i = i mod m in
              let j = j mod m in
              let k = k mod m in i*m*m + j*m + k;;


let inc a i j = a.(i*s+j) <- a.(i*s+j) + 1;;

for i = 0 to m - 1 do
  for j = 0 to m - 1 do
    for k = 0 to m - 1 do
      inc a (f (i+1) j k) (f i j k);
      inc a (f i (j+i) k) (f i j k);
      inc a (f i j (k+j)) (f i j k);
    done
  done
done;;

let a = power a n;;
let ans = ref 0;;
for i = 0 to m - 1 do
  for j = 0 to m - 1 do
    ans := (!ans + a.(f i j 0)) mod md;
  done 
done;;

print_int !ans;;
print_newline ();;
0