結果

問題 No.178 美しいWhitespace (1)
ユーザー togaerror
提出日時 2015-04-11 18:01:56
言語 Perl
(5.40.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 513 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-07-04 13:38:51
合計ジャッジ時間 7,400 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/perl

use strict;
use warnings;
use bigint;

my $n = <>;
my @arraya;
my @arrayb;
my @count;
for(my $i = 0; $i < $n; $i++) {
	($arraya[$i], $arrayb[$i] )= split / /, <>;
	$count[$i] = $arraya[$i] + 4 * $arrayb[$i];
}

@count = reverse sort {$a <=> $b} @count;
my $ans = 0;

for(my $i = 1; $i < $n; $i++) {
	if(($count[0] - $count[$i]) % 2 eq 0) {
		my $c = $count[0] - $count[$i];
		$ans += $c / 2;
	} else {
		$ans = -1;
		last;
	}
}

if($ans  < 0) {
	print "$ans\n";
} else {
	print "$ans\n";
}

exit;
0