結果

問題 No.273 回文分解
ユーザー es
提出日時 2015-09-26 20:50:47
言語 PHP
(843.2)
結果
RE  
実行時間 -
コード長 793 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 30,748 KB
実行使用メモリ 31,548 KB
最終ジャッジ日時 2024-12-23 12:00:25
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$ans = 1;

$s = trim(fgets(STDIN));
$r = strrev($s);
$s = str_split($s);
$r = str_split($r);
$a = array();

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

$h = array_shift($a);
$c = count($h);
if ($c > 2) {
  $ans = $c;
} else if ($c == 2){
  if ($h[0] === $h[1]) {
    $ans = 1;
  }
}
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, ""))) {
            $a[] = $l;
          }
        }
        $l = array();
      }
    }

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