結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-21 07:41:37 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,147 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 33,408 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-16 10:16:42 |
| 合計ジャッジ時間 | 1,051 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 6 |
ソースコード
module mdl
contains
recursive subroutine qsort(a,s,t)
integer*8::a(:),i,j,s,t,m
if(t-s<=1)return
i=s
j=t-1
m=a((s+t)/2)
do
do while(a(i)<m)
i=i+1
end do
do while(a(j)>m)
j=j-1
end do
if(i>=j)exit
a(i)=xor(a(i),a(j))
a(j)=xor(a(i),a(j))
a(i)=xor(a(i),a(j))
i=i+1
j=j-1
end do
call qsort(a,s,i)
call qsort(a,j+1,t)
end subroutine
function calc(c,trg)
integer*8::calc,c(:),trg
calc=0
do i=1,size(c)
calc=calc+abs(c(i)-trg)
end do
end function
end module
program main
use mdl
implicit none
integer*8::b,n,tot=0,i,j,k,s,t,ans
integer*8,allocatable::c(:)
read*,b
read*,n
tot=tot+b
allocate(c(n))
do i=1,n
read*,c(i)
tot=tot+c(i)
end do
call qsort(c,int(1,8),int(size(c),8))
ans=calc(c,tot/n)
if(tot/n>c((n+1)/2))then
ans=min(ans,calc(c,c((n+1)/2)))
end if
print*,ans
end program