結果

問題 No.390 最長の数列
ユーザー jjjj
提出日時 2016-08-10 23:46:00
言語 Fortran
(gFortran 13.2.0)
結果
TLE  
実行時間 -
コード長 947 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 35,404 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-25 01:10:31
合計ジャッジ時間 8,104 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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
  interface
     recursive function qsort(x) result(y)
       integer,intent(in) ::x(:)
       integer,allocatable::y(:)
     end function qsort
  end interface
  integer::N,i,j,max_len,tmp, tmp2
  integer,allocatable::x(:),y(:),dp(:)
  read *, N
  allocate(x(N),y(N),dp(N))
  read *, x

  y = qsort(x)
  ! max length of good series @ index num
  dp = 1
  do i=2, N
     max_len = 0
     do j=1,i-1
        if(MOD(y(i),y(j)).eq.0) then
           max_len = MAX(max_len, dp(j))
        end if
     end do
     dp(i) = max_len + 1
  end do
  print '(i0)', MAXVAL(dp)

end program main
0