結果
| 問題 | No.273 回文分解 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-26 21:10:54 |
| 言語 | PHP (843.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 904 bytes |
| コンパイル時間 | 560 ms |
| コンパイル使用メモリ | 31,200 KB |
| 実行使用メモリ | 31,632 KB |
| 最終ジャッジ日時 | 2024-12-23 12:01:31 |
| 合計ジャッジ時間 | 3,005 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 22 WA * 10 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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);
}