結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2018-05-26 01:05:47 |
| 言語 | Perl (5.40.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 1,000 ms |
| コード長 | 886 bytes |
| コンパイル時間 | 60 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-06-28 18:07:22 |
| 合計ジャッジ時間 | 1,003 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
Main.pl syntax OK
ソースコード
#!/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";
moti