結果

問題 No.2441 行列累乗
ユーザー osada-yumosada-yum
提出日時 2023-09-25 16:34:42
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 29,980 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 16:34:46
合計ジャッジ時間 2,952 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program yukicoder_2441
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32), parameter :: n = 2
  integer(int32) :: m(n, n)
  read(input_unit, *) m(1, :), m(2, :)
  m(:, :) = pow_mat(n, m, 3)
  write(output_unit, '(*(i0, 1x))') m(1, :)
  write(output_unit, '(*(i0, 1x))') m(2, :)
contains
  pure recursive function pow_mat(n, mat, p) result(res)
    integer(int32), intent(in) :: n, mat(n, n)
    integer(int32), intent(in) :: p
    integer(int32) :: res(n, n)
    integer(int32) :: i, j, k
    if (p == 0) then
       res(:, :) = 0
       do i = 1, n
          res(i, i) = 1
       end do
       return
    end if
    !> p /= 0
    if (iand(p, b'1') == 0) then
       res(:, :) = pow_mat(n, matmul(mat, mat), p / 2)
    else
       res(:, :) = matmul(mat, pow_mat(n, mat, p - 1))
    end if
  end function pow_mat
end program yukicoder_2441
0