結果

問題 No.588 空白と回文
ユーザー motimoti
提出日時 2018-05-26 00:14:03
言語 Perl
(5.38.2)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 6,196 KB
実行使用メモリ 6,348 KB
最終ジャッジ日時 2023-09-11 03:33:49
合計ジャッジ時間 2,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,076 KB
testcase_01 AC 14 ms
6,164 KB
testcase_02 AC 14 ms
6,172 KB
testcase_03 AC 168 ms
6,264 KB
testcase_04 AC 14 ms
6,348 KB
testcase_05 AC 14 ms
6,260 KB
testcase_06 AC 14 ms
6,200 KB
testcase_07 AC 14 ms
6,164 KB
testcase_08 AC 14 ms
6,164 KB
testcase_09 AC 14 ms
6,108 KB
testcase_10 AC 14 ms
6,084 KB
testcase_11 AC 165 ms
6,236 KB
testcase_12 AC 155 ms
6,120 KB
testcase_13 AC 13 ms
6,176 KB
testcase_14 AC 14 ms
6,164 KB
testcase_15 AC 14 ms
6,160 KB
testcase_16 AC 13 ms
6,104 KB
testcase_17 AC 109 ms
6,252 KB
testcase_18 AC 14 ms
6,080 KB
testcase_19 AC 13 ms
6,104 KB
testcase_20 AC 159 ms
6,232 KB
testcase_21 AC 136 ms
6,236 KB
testcase_22 AC 155 ms
6,148 KB
testcase_23 AC 100 ms
6,244 KB
testcase_24 AC 14 ms
6,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

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

my $line = <>; chomp $line;
unless (length $line) {
  print 0;
  exit;
}

my @arr = split //,$line;
my $max = 1;
for (my $cent = 0; $cent < scalar @arr; $cent++) {
  my $count = 1;
  for (my $i = 1; ; $i++) {
    my $left = $cent - $i;
    my $right = $cent + $i;
    last if $left < 0;
    last if $right >= scalar @arr;
    $count += 2 if $arr[$left] eq $arr[$right];
  }
  $max = $count if $max < $count;

  $count = 0;
  for (my $i = 1; ; $i++) {
    my $left = $cent - $i + 1;
    my $right = $cent + $i;
    last if $left < 0;
    last if $right >= scalar @arr;
    $count += 2 if $arr[$left] eq $arr[$right];
  }
  $max = $count if $max < $count;
}

print $max;
0