結果

問題 No.273 回文分解
ユーザー eses
提出日時 2015-09-26 21:10:54
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 18,708 KB
実行使用メモリ 19,300 KB
最終ジャッジ日時 2023-08-25 00:21:21
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
19,004 KB
testcase_02 AC 16 ms
19,000 KB
testcase_03 AC 16 ms
18,892 KB
testcase_04 AC 16 ms
18,980 KB
testcase_05 WA -
testcase_06 AC 16 ms
19,036 KB
testcase_07 AC 16 ms
19,100 KB
testcase_08 AC 16 ms
19,064 KB
testcase_09 AC 16 ms
19,008 KB
testcase_10 AC 16 ms
19,096 KB
testcase_11 AC 16 ms
18,936 KB
testcase_12 AC 16 ms
18,964 KB
testcase_13 AC 16 ms
19,092 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 16 ms
18,904 KB
testcase_17 AC 16 ms
19,096 KB
testcase_18 AC 15 ms
19,004 KB
testcase_19 AC 16 ms
19,020 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 17 ms
18,940 KB
testcase_23 AC 16 ms
18,892 KB
testcase_24 AC 16 ms
19,004 KB
testcase_25 AC 16 ms
18,888 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 16 ms
19,124 KB
testcase_30 AC 17 ms
19,092 KB
testcase_31 AC 16 ms
18,936 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 17 ms
19,064 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$ans = 1;

$s = trim(fgets(STDIN));
$r = strrev($s);
if (strlen($s) <= 2) {
  if ($s === $r) {
    echo 1 . PHP_EOL;
    exit;
  }
}

$s = str_split($s);
$r = str_split($r);
$a = array();

scanning($s, $r, $a);
scanning($r, $s, $a);

$h = array_shift($a);
$ans = count($h);

preg_match_all('/(.)\1/', implode($h), $out);
if (isset($out[0]) && $ans > 2) {
  $ans = $ans - count($out[0]) * 2;
}
echo $ans . PHP_EOL;

function scanning($from, $to, &$a) {
  for($i=0;$i < count($to); $i++) {
    $o = array_intersect_assoc($from, $to);

    $l = array();
    foreach((array)$o as $k => $v) {
      $l[] = $v;
      if (!isset($o[$k+1])) {
        if (implode($l) === strrev(implode($l)) ) {
          if (strpos(implode($to), implode($l)) !== false) {
            $a[] = $l;
          }
        }
        $l = array();
      }
    }

    array_shift($from);
    array_merge($from);
  }
  arsort($a);
}
0