結果

問題 No.357 品物の並び替え (Middle)
ユーザー AuthnsAuthns
提出日時 2020-10-18 19:58:09
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 637 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 28,396 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 12:03:33
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32)n,m,n2,s,ns,i,j
    integer(int32):: i1,i2,sc
    integer(int32), allocatable:: score(:,:),dp(:)

    read*, n,m
    allocate(score(n,n), source=0)
    do i=1,m
        read*, i1,i2,sc
        score(i1+1,i2+1) = sc
    end do
    n2 = lshift(1,n)-1
    allocate(dp(0:n2),source=0)

    do s=0,n2
        do i=1,n
            if (btest(s,i-1)) cycle
            ns = ibset(s,i-1)
            sc=sum([(merge(score(i,j),0,btest(s,j-1)),j=1,n)])
            dp(ns) = max(dp(ns), dp(s)+sc)
        end do
    end do
    print'(i0)', dp(n2)
end program main
0