結果

問題 No.4 おもりと天秤
ユーザー togaerrortogaerror
提出日時 2015-04-21 17:56:51
言語 Perl
(5.38.2)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 5,828 KB
最終ジャッジ日時 2023-09-18 02:18:43
合計ジャッジ時間 3,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,608 KB
testcase_01 AC 5 ms
4,904 KB
testcase_02 AC 44 ms
5,536 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 248 ms
5,564 KB
testcase_06 WA -
testcase_07 AC 248 ms
5,560 KB
testcase_08 AC 5 ms
4,764 KB
testcase_09 AC 247 ms
5,548 KB
testcase_10 AC 247 ms
5,604 KB
testcase_11 AC 25 ms
5,548 KB
testcase_12 AC 15 ms
5,464 KB
testcase_13 AC 15 ms
5,552 KB
testcase_14 AC 17 ms
5,560 KB
testcase_15 AC 15 ms
5,508 KB
testcase_16 WA -
testcase_17 AC 24 ms
5,796 KB
testcase_18 WA -
testcase_19 AC 247 ms
5,584 KB
testcase_20 AC 247 ms
5,676 KB
testcase_21 AC 249 ms
5,712 KB
testcase_22 AC 248 ms
5,744 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/env perl

use strict;
use warnings;

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

@array = sort {$a <=> $b} @array;
for(my $i = 0; $i < $n; $i++) {
	$ans += $array[$i];
}
$ans /= 2;
if($ans != int $ans) {
	print "impossible\n";
	exit;
}
my @f;
my @s;

for(my $i = 0; $i < 100**2; $i++) {
	$f[$i] = 0;
	$s[$i] = 0;
}
for(my $i = 0; $i < $n; $i++) {
	$f[$array[$i]] = 1;
}

for(my $i = 0; $i < $n; $i++) {
	for(my $j = 0; $j < 100**2; $j++) {
		if(($array[$i] + $j < 100**2)and($f[$j] == 1)) {
				$s[$j + $i] = 1;
		}
	}
	for(my $k = 0; $k < 100**2; $k++) {
		if(($f[$k] == 1)or($s[$k] == 1)) {
			$f[$k] = 1;
		}
	}
}
#for(my $i = 0; $i < 10; $i++) {
#	print "$s[$i]" ;
#}
#print "\n";
if($s[$ans] == 1) {
	print "possible\n";
} else {
	print "impossible\n";
}

exit;
0