結果

問題 No.198 キャンディー・ボックス2
ユーザー 37zigen37zigen
提出日時 2018-04-21 07:37:13
言語 Fortran
(gFortran 13.2.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 28,152 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-09 12:17:18
合計ジャッジ時間 1,685 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    allocate(c(n))
    do i=1,n
        read*,c(i)
    end do

    call qsort(c,int(1,8),int(size(c),8))

    print*,calc(c,c((n+1)/2))
end program
0