結果

問題 No.107 モンスター
ユーザー AuthnsAuthns
提出日時 2020-10-18 20:19:08
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 739 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 28,476 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2023-09-28 12:03:43
合計ジャッジ時間 1,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 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 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 26 ms
4,508 KB
testcase_15 AC 26 ms
4,632 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 46 ms
6,896 KB
testcase_19 AC 47 ms
6,944 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 25 ms
4,636 KB
testcase_23 AC 50 ms
6,876 KB
testcase_24 AC 48 ms
6,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,n2,s,ns,i,j,lv,hp
    integer(int32), allocatable:: d(:),dp(:,:)

    read*, n
    n2 = lshift(1,n)-1
    allocate(d(n))
    read*, d(:)
    allocate(dp(n+1,0:n2), source=-100100100)
    dp(1,0) = 100

    do s=0,n2; do lv=1,n
        do i=1,n
            ns = ibset(s,i-1)
            if (ns==s) cycle
            if (dp(lv,s)+d(i) <= 0) cycle 
            hp = min(dp(lv,s) + d(i), lv*100)
            if (d(i) < 0) then
                dp(lv+1,ns) = max(dp(lv+1,ns), hp)
            else
                dp(lv,ns) = max(dp(lv,ns), hp)
            end if
        end do
    end do; end do
    print'(i0)', max(maxval(dp(:,n2)),0)
end program main
0