結果

問題 No.193 筒の数式
ユーザー motimoti
提出日時 2018-05-26 00:34:14
言語 Perl
(5.38.2)
結果
WA  
実行時間 -
コード長 891 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 6,400 KB
実行使用メモリ 6,352 KB
最終ジャッジ日時 2023-09-11 03:33:58
合計ジャッジ時間 1,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 14 ms
6,244 KB
testcase_03 AC 15 ms
6,196 KB
testcase_04 AC 15 ms
6,096 KB
testcase_05 AC 15 ms
6,076 KB
testcase_06 AC 14 ms
6,260 KB
testcase_07 AC 14 ms
6,232 KB
testcase_08 AC 14 ms
6,260 KB
testcase_09 AC 14 ms
6,164 KB
testcase_10 AC 13 ms
6,340 KB
testcase_11 AC 14 ms
6,232 KB
testcase_12 AC 13 ms
6,080 KB
testcase_13 AC 13 ms
6,216 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 0;

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 $ea[0] eq '+' || $ea[0] eq '-';
  next if $ea[@ea-1] eq '+' || $ea[@ea-1] eq '-';
  my @nea;
  my $nldz = 0;
  for my $c (@ea) {
    $nldz = 1 unless $c eq '0';
    push @nea, $c if $nldz == 1;
    $nldz = 0 if is_op $c;
  }
  unshift @nea, '0' if is_op $nea[0];
  my @nnea;
  for (my $i = 0; $i < @nea - 1; $i++) {
    push @nnea, $nea[$i];
    if (is_op $nea[$i] && is_op $nea[$i+1]) {
      push @nnea, '0';
    }
  }
  push @nnea, $nea[@nea-1];
#  print join('', @nnea) . "\n";
  my $cand = eval(join('', @nnea));
  $ma = $cand if $ma < $cand;
}
print "$ma\n";
0