結果

問題 No.45 回転寿司
ユーザー jjjj
提出日時 2016-07-23 14:49:59
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,897 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 27,412 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 14:55:30
合計ジャッジ時間 2,414 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

recursive function get_max(part, length) result(res)
  implicit none
  integer::part(*)
  integer::length,x,y
  integer::res(2,2),first(2,2),second(2,2)
  integer::plength
  integer,parameter::on=1,off=2
  if (length.ge.4) then
     plength = length/2
     first  = get_max(part(1:plength),plength)
     second = get_max(part(plength+1:length),length-plength)
     res(on,on)   = MAXVAL((/first(on,off)+second(off,on), &
                             first(on,off)+second(on, on), &
                             first(on, on)+second(off,on)/))
     res(on,off)  = MAXVAL((/first(on,off)+second(off,off), &
                             first(on,off)+second(on, off), &
                             first(on, on)+second(off,off)/))
     res(off,on)  = MAXVAL((/first(off,off)+second(off,on), &
                             first(off,off)+second(on, on), &
                             first(off, on)+second(off,on)/))
     res(off,off) = MAXVAL((/first(off,off)+second(off,off), &
                             first(off,off)+second(on, off), &
                             first(off, on)+second(off,off)/))
  else if(length.eq.3) then
     res(on,on)   = MAX(part(1)+part(3),part(2))
     res(on,off)  = MAX(part(1),part(2))
     res(off,on)  = MAX(part(2),part(3))
     res(off,off) = part(2)
  else if(length.eq.2) then
     res(on,on)   = MAX(part(1),part(2))
     res(on,off)  = part(1)
     res(off,on)  = part(2)
     res(off,off) = 0
  end if

end function get_max

program main
  implicit none
  interface
     recursive function get_max(part, length) result(res)
       integer::part(*)
       integer::length
       integer::res(2,2)
     end function get_max
  end interface
  integer::N
  integer::oisisa(2,2)
  integer::V(1000)
  read *, N
  read *, V(1:N)

  if(N.eq.1) then
     oisisa=V(1)
  else
     oisisa = get_max(V(1:N),N)
  end if
  print '(i0)',MAXVAL(oisisa)
end program main
0