結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 2016-10-16 15:18:23 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 5,000 ms |
| コード長 | 1,303 bytes |
| コンパイル時間 | 2,021 ms |
| コンパイル使用メモリ | 35,632 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-22 11:58:36 |
| 合計ジャッジ時間 | 3,401 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
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
jj