結果

問題 No.4 おもりと天秤
ユーザー kuroi_13kuroi_13
提出日時 2017-01-27 09:53:26
言語 Perl
(5.38.2)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 5,340 KB
実行使用メモリ 5,252 KB
最終ジャッジ日時 2023-08-25 03:21:32
合計ジャッジ時間 1,413 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

use strict;
use warnings;

my $num = <STDIN>;
my @w = split(' ', <STDIN>);

my $half = $num % 2 == 0 ? $num/2-1 : $#w/2;
my @ary_a = sort {$a <=> $b} @w[0..$half];
my @ary_b = sort {$a <=> $b} @w[$half+1..$#w];

my @sum;
my %store;

for(;;){
  @sum = (0, 0);
  $sum[0] = eval join('+', @ary_a);
  $sum[1] = eval join('+', @ary_b);

  if(defined($store{$sum[0]}) and defined($store{$sum[1]})){
    print 'impossible';
    last;
  }else{
    $store{$sum[0]} = 1;
    $store{$sum[1]} = 1;
  }

  print $sum[0].' '.$sum[1]."\n";
  if($sum[0] > $sum[1]){
    push @ary_b, shift @ary_a;
    @ary_b = sort {$a <=> $b} @ary_b;
  }elsif($sum[0] < $sum[1]){
    push @ary_a, shift @ary_b;
    @ary_a = sort {$a <=> $b} @ary_a;
  }else{
    print 'possible';
    last;
  }
}
0