結果

問題 No.390 最長の数列
ユーザー jjjj
提出日時 2016-08-11 00:05:50
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 1,475 ms
コンパイル使用メモリ 34,992 KB
実行使用メモリ 8,560 KB
最終ジャッジ日時 2024-04-10 10:05:16
合計ジャッジ時間 2,521 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 72 ms
6,940 KB
testcase_06 AC 71 ms
7,924 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 80 ms
8,560 KB
testcase_11 AC 79 ms
8,344 KB
testcase_12 AC 79 ms
8,380 KB
testcase_13 AC 49 ms
7,652 KB
testcase_14 AC 76 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 8 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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,max_val
  integer,allocatable::x(:),y(:)
  integer::dp(10**6)
  data dp/1000000*0/
  read *, N
  allocate(x(N),y(N))
  read *, x

  y = qsort(x)
  max_val = y(N)

  do i=1,N
     dp(y(i)) = 1
  end do


  max_len = 1
  do i=1,N
     tmp  = y(i)
     tmp2 = dp(y(i))
     do j = tmp+tmp, max_val, tmp
        dp(j) = MAX(dp(j), tmp2 + 1)
     end do
     max_len = MAX(max_len, dp(y(i)))
  end do

  print '(i0)', max_len
end program main
0