結果

問題 No.45 回転寿司
ユーザー jj
提出日時 2016-07-23 14:49:20
言語 Fortran
(gFortran 14.2.0)
結果
WA  
実行時間 -
コード長 1,922 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 32,768 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 17:12:27
合計ジャッジ時間 1,224 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

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 '(2i5)',oisisa
  print '(i0)',MAXVAL(oisisa)

end program main
0