結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー jjjj
提出日時 2016-10-16 15:18:23
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 1,303 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 30,304 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-08-14 14:15:59
合計ジャッジ時間 3,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
4,376 KB
testcase_01 AC 125 ms
4,376 KB
testcase_02 AC 55 ms
4,376 KB
testcase_03 AC 123 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::T,N,i,j,k,prev,num
  integer*8::L(100),S(100),hist(100),shist(100)
  read *,T

  do i=1,T
     read *,N
     read *,L(1:N)
     S(1:N) = qsortr(L(1:N))
     hist = 0
     prev = -1
     k = 0
     do j=1, N
        if(prev.eq.S(j)) then
           hist(k) = hist(k) + 1
        else
           k = k + 1
           hist(k) = 1
           prev = S(j)
        end if
     end do
     if(k.lt.3) then
        print '(i0)',0
        cycle
     end if
     shist(1:k) = qsortr(hist(1:k))
     num = 0
     do while(shist(3).ne.0)
        num = num + 1
        shist(1:3) = shist(1:3) - 1
        hist = shist
        shist(1:k) = qsortr(hist(1:k))
     end do
     print '(i0)', num
  end do
contains
  subroutine printer(L,N)
    integer*8::L(:),N,i
    do i=1,N
       write(*,'(i0," ")',advance='no') L(i)
    end do
    write (*,*)
  end subroutine printer
  recursive function qsortr(x) result(y)
    integer*8,intent(in) ::x(:)
    integer*8,allocatable::y(:)
    integer*8::pivot,total
    total = size(x)
    if (total <=1) then
       y = x
    else
       pivot = x(total/2)
       y = [qsortr(pack(x, x .gt. pivot)), &
            pack(x, x .eq. pivot),        &
            qsortr(pack(x, x .lt. pivot))]
    endif
  end function qsortr
end program main
0