結果

問題 No.4 おもりと天秤
ユーザー osada-yumosada-yum
提出日時 2023-10-30 16:17:46
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 821 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 33,772 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-10-30 16:17:50
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

program yukicoder_4
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32) :: n, sum_w
  integer(int32), allocatable :: ws(:)
  logical, allocatable :: dp(:, :)
  integer(int32) :: i, j, bef
  read(input_unit, *) n
  allocate(ws(n))
  read(input_unit, *) ws(:)
  sum_w = sum(ws(:))
  if (iand(sum_w, b'1') == 1) then
     write(output_unit, '(a)') "impossible"
     stop
  end if
  !> sum_w is even.
  allocate(dp(0:sum_w / 2, 0:n), source = .false.)
  dp(0, 0) = .true.
  do i = 1, n
     dp(:, i) = dp(:, i - 1)
     do j = 0, sum_w / 2
        bef = j - ws(i)
        if (bef < 0) cycle
        !> bef >= 0
        if (.not. dp(bef, i - 1)) cycle
        dp(j, i) = .true.
     end do
  end do
  write(output_unit, '(a)') trim(merge("possible  ", "impossible", dp(sum_w / 2, n)))
end program yukicoder_4
0