結果

問題 No.273 回文分解
ユーザー es
提出日時 2015-09-26 20:55:48
言語 PHP
(843.2)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 32,400 KB
実行使用メモリ 32,532 KB
最終ジャッジ日時 2024-12-23 12:01:09
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)) !== false) {
            $a[] = $l;
          }
        }
        $l = array();
      }
    }

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