結果

問題 No.393 2本の竹
ユーザー takeya_okinotakeya_okino
提出日時 2017-08-06 12:04:23
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 32,148 KB
実行使用メモリ 123,036 KB
最終ジャッジ日時 2024-04-20 03:50:13
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$d = trim(fgets(STDIN));
for($i = 0; $i < $d; $i++) {
  $array = explode(" ", trim(fgets(STDIN)));
  $n1 = $array[0];
  $n2 = $array[1];
  $m = trim(fgets(STDIN));
  $a = explode(" ", trim(fgets(STDIN)));
  sort($a);
  $sum = array();
  $sum[0] = $a[0];
  for($j = 1; $j < $m; $j++) {
    $sum[$j] = $sum[$j - 1] + $a[$j];
  }
  // $dp[i][j]は竹1の長さj,竹2の長さ($n1+$n2-j-$sum[$i - 1])の場合に要求竹i以上で提供できる最大数を表す
  $dp = array();
  for($j = 0; $j <= $n1 + $n2 - $sum[$m - 1]; $j++) {
    if(($j >= $a[$m - 1]) || ($n1 + $n2 - $sum[$m - 1] - $j >= $a[$m - 1])) {
      $dp[$m - 1][$j] = 1;
    } else {
      $dp[$m - 1][$j] = 0;
    }
  }
  for($j = $m - 2; $j >= 0; $j--) {
    for($k = 0; $k <= $n1 + $n2 - $sum[$j - 1]; $k++) {
      $dp[$j][$k] = 0;
      if($k >= $a[$j]) {
        $dp[$j][$k] = max($dp[$j][$k], 1 + $dp[$j + 1][$k - $a[$j]]);
      }
      if($n1 + $n2 - $sum[$j - 1] - $k >= $a[$j]) {
        $dp[$j][$k] = max($dp[$j][$k], 1 + $dp[$j + 1][$k]);
      }
    }
  }
  print($dp[0][$n1]);
  print("\n");
}
?>
0