結果

問題 No.4 おもりと天秤
ユーザー yuma25689yuma25689
提出日時 2015-11-03 14:18:09
言語 PHP
(8.3.4)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 1,016 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 18,508 KB
実行使用メモリ 18,956 KB
最終ジャッジ日時 2023-09-08 16:27:54
合計ジャッジ時間 3,231 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,956 KB
testcase_01 AC 18 ms
18,800 KB
testcase_02 AC 26 ms
18,800 KB
testcase_03 AC 23 ms
18,620 KB
testcase_04 AC 26 ms
18,952 KB
testcase_05 AC 83 ms
18,812 KB
testcase_06 AC 17 ms
18,840 KB
testcase_07 AC 83 ms
18,660 KB
testcase_08 AC 79 ms
18,948 KB
testcase_09 AC 84 ms
18,952 KB
testcase_10 AC 83 ms
18,848 KB
testcase_11 AC 20 ms
18,780 KB
testcase_12 AC 17 ms
18,788 KB
testcase_13 AC 17 ms
18,776 KB
testcase_14 AC 18 ms
18,808 KB
testcase_15 AC 18 ms
18,856 KB
testcase_16 AC 21 ms
18,660 KB
testcase_17 AC 21 ms
18,848 KB
testcase_18 AC 82 ms
18,792 KB
testcase_19 AC 83 ms
18,904 KB
testcase_20 AC 82 ms
18,868 KB
testcase_21 AC 82 ms
18,872 KB
testcase_22 AC 83 ms
18,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?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);
0