結果

問題 No.193 筒の数式
ユーザー motimoti
提出日時 2018-05-26 01:07:28
言語 Perl
(5.38.2)
結果
AC  
実行時間 15 ms / 1,000 ms
コード長 843 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 6,436 KB
実行使用メモリ 6,388 KB
最終ジャッジ日時 2023-09-11 03:34:05
合計ジャッジ時間 1,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,260 KB
testcase_01 AC 14 ms
6,204 KB
testcase_02 AC 14 ms
6,108 KB
testcase_03 AC 14 ms
6,264 KB
testcase_04 AC 15 ms
6,060 KB
testcase_05 AC 14 ms
6,280 KB
testcase_06 AC 14 ms
6,160 KB
testcase_07 AC 14 ms
6,212 KB
testcase_08 AC 14 ms
6,108 KB
testcase_09 AC 14 ms
6,164 KB
testcase_10 AC 14 ms
6,256 KB
testcase_11 AC 14 ms
6,300 KB
testcase_12 AC 14 ms
6,080 KB
testcase_13 AC 14 ms
6,080 KB
testcase_14 AC 14 ms
6,164 KB
testcase_15 AC 14 ms
6,368 KB
testcase_16 AC 14 ms
6,112 KB
testcase_17 AC 14 ms
6,388 KB
testcase_18 AC 14 ms
6,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

my $s = <>; chomp $s;
my $n = length $s;
my @sa = split //, $s . $s;
my $ma = -9999999999;

sub is_op {
  my $ch = shift;
  $ch eq '+' || $ch eq '-';
}

for (my $i = 0; $i < $n; $i++) {
  my @ea = @sa[$i..($i+$n-1)];
  next if is_op($ea[0]) || is_op($ea[@ea-1]);
  my @nea;
  my $ldz = 1;
  for my $c (@ea) {
    $ldz = 0 if $c ne '0';
    push @nea, $c unless $ldz;
    $ldz = 1 if is_op $c;
  }
  unshift @nea, '0' if is_op $nea[0];
  push @nea, '0' if is_op $nea[@nea-1];
  my @nnea;
  for (my $i = 0; $i < @nea; $i++) {
    push @nnea, $nea[$i];
    if ($i > 0 && is_op($nnea[$i - 1]) && is_op($nnea[$i])) {
      my $la = pop @nnea;
      push @nnea, '0';
      push @nnea, $la;
    }
  }
  my $cand = eval(join('', @nnea));
  $ma = $cand if $ma < $cand;
}
print "$ma\n";
0