結果

問題 No.4 おもりと天秤
ユーザー togaerrortogaerror
提出日時 2015-04-21 23:47:52
言語 Perl
(5.38.0)
結果
AC  
実行時間 192 ms / 5,000 ms
コード長 868 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 5,220 KB
実行使用メモリ 5,828 KB
最終ジャッジ日時 2023-09-08 16:14:47
合計ジャッジ時間 3,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
5,736 KB
testcase_01 AC 5 ms
5,072 KB
testcase_02 AC 34 ms
5,544 KB
testcase_03 AC 25 ms
5,752 KB
testcase_04 AC 33 ms
5,704 KB
testcase_05 AC 192 ms
5,576 KB
testcase_06 AC 11 ms
5,748 KB
testcase_07 AC 187 ms
5,648 KB
testcase_08 AC 5 ms
5,092 KB
testcase_09 AC 172 ms
5,760 KB
testcase_10 AC 192 ms
5,544 KB
testcase_11 AC 19 ms
5,820 KB
testcase_12 AC 13 ms
5,632 KB
testcase_13 AC 13 ms
5,828 KB
testcase_14 AC 15 ms
5,796 KB
testcase_15 AC 12 ms
5,824 KB
testcase_16 AC 21 ms
5,540 KB
testcase_17 AC 19 ms
5,696 KB
testcase_18 AC 181 ms
5,708 KB
testcase_19 AC 187 ms
5,712 KB
testcase_20 AC 187 ms
5,796 KB
testcase_21 AC 186 ms
5,764 KB
testcase_22 AC 186 ms
5,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/evn perl

use strict;
use warnings;

my $n = <>;
my $str = <>;
chomp $str;
my @array = split / /, $str;

my @first;
my @second;

my $res = 0;
for(my $h = 0; $h < $n; $h++) {
	$res += $array[$h];
}
$res /= 2;
if($res != int $res) {
	print "impossible\n";
	exit;
}

#配列の初期化
for(my $i = 0; $i < 100**2; $i++) {
	$first[$i] = 0;
	$second[$i] = 0;
}

$first[0] = 1;

#入力した数字だけ調べる
for(my $i = 0; $i < $n; $i++) {
	#0..100で1があるところを調べる
	for(my $j = 0; $j < 100**2; $j++) {
		#もし1があった時
		if($first[$j] == 1) {
			$second[$array[$i] + $j] = 1;
		}
	}
	#firstとsecondを合わせて、firstに格納
	for(my $k = 0; $k < 100**2; $k++) {
		if(($first[$k] == 1)or($second[$k] == 1)) {
			$first[$k] = 1;
		}
	}
}

if($first[$res] == 1) {
	print "possible\n";
} else {
	print "impossible\n";
}

exit;
0