結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
yuma25689
|
| 提出日時 | 2015-11-03 14:18:09 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 110 ms / 5,000 ms |
| コード長 | 1,016 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 30,916 KB |
| 実行使用メモリ | 31,504 KB |
| 最終ジャッジ日時 | 2024-06-26 09:20:39 |
| 合計ジャッジ時間 | 2,919 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php
// 2 <= count <= 100
$count = trim(fgets(STDIN));
// 1 <= weight <= 100
$weight=explode(' ',trim(fgets(STDIN)));
//var_dump($weight);
const MAX=10000;
$CombinationOfThisWeightExist = array_fill(0,MAX,False);
$CombinationOfThisWeightExist[0] = True;
$sum = 0;
for( $i=0; $i<$count; $i++ )
{
// 重りの数分ループ
// 重りの合計値取得
$sum += $weight[$i];
// 重り毎に、その重りの内容ですべてのメモ配列を更新
for( $j=MAX-1-$weight[$i]; 0<=$j; $j-- )
{
// すでにその組み合わせがある重さに、現在の重りを足した重さも、その組み合わせがあると考えられる
$CombinationOfThisWeightExist[$j+$weight[$i]] |= $CombinationOfThisWeightExist[$j];
}
}
//print($sum.PHP_EOL);
// for( $i < 0; $i < MAX; $i++ )
// {
// if( $CombinationOfThisWeightExist[$i] == True )
// print($i.PHP_EOL);
// }
if( $sum % 2 != 0 || $CombinationOfThisWeightExist[$sum / 2] == False )
print('impossible'.PHP_EOL);
else
print('possible'.PHP_EOL);
yuma25689