結果

問題 No.110 しましまピラミッド
ユーザー jj
提出日時 2016-08-11 20:55:59
言語 Fortran
(gFortran 14.2.0)
結果
WA  
実行時間 -
コード長 1,711 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 35,636 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-07 11:04:03
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

recursive function qsort(x) result(y)
  integer,intent(in) ::x(:)
  integer,allocatable::y(:)
  integer::pivot,total
  total = size(x)
  if (total <=1) then
     y = x
  else
     pivot = x(total/2)
     y = [qsort(pack(x, x .lt. pivot)), &
          pack(x, x .eq. pivot),        &
          qsort(pack(x, x .gt. pivot))]
  endif
end function qsort

program main
  implicit none
  interface
     recursive function qsort(x) result(y)
       integer,intent(in) ::x(:)
       integer,allocatable::y(:)
     end function qsort
  end interface
  integer::NW,NB
  integer,allocatable::W(:),B(:)
  integer,allocatable::WS(:),BS(:)
  integer::i,j,top,itrw,itrb,maxw,maxb,height
  read *,NW
  allocate(W(NW),WS(NW))
  read *,W
  read *,NB
  allocate(B(NB),BS(NB))
  read *,B

  WS = qsort(W)
  BS = qsort(B)
  top = BS(NB)
  height = 1
  do
     do itrw=NW, 1,-1
        if(WS(itrw).lt.top) then
           top = WS(itrw)
           height = 1 + height
           exit
        end if
     end do
     do itrb=NB, 1,-1
        if(BS(itrb).lt.top) then
           top = BS(itrb)
           height = 1 + height
           exit
        end if
     end do
     if(itrw.eq.0.or.itrb.eq.0) then
        exit
     end if

  end do

  maxw = height
  top = WS(NW)
  height = 1
  do
     do itrb=NB, 1,-1
        if(BS(itrb).lt.top) then
           top = BS(itrb)
           height = 1 + height
           exit
        end if
     end do
     do itrw=NW, 1,-1
        if(WS(itrw).lt.top) then
           top = WS(itrw)
           height = 1 + height
           exit
        end if
     end do
     if(itrw.eq.0.or.itrb.eq.0) then
        exit
     end if
  end do
  maxb = height

  print '(i0)', MAX(maxw,maxb)
end program main
0