結果
問題 | No.273 回文分解 |
ユーザー |
![]() |
提出日時 | 2015-09-26 02:42:16 |
言語 | PHP (843.2) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 961 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 31,080 KB |
実行使用メモリ | 31,380 KB |
最終ジャッジ日時 | 2024-06-25 13:30:17 |
合計ジャッジ時間 | 2,841 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?phpfunction str_continuity($str){//------------------------//連続する文字列を数える//------------------------$p = array();for ($s=0; $s<count($str); $s++){$p[$s] = 1;for ($nxt=$s+1; $nxt<count($str); $nxt++){if ($str[$s]==$str[$nxt]){$p[$s]++;}else{break;}}}return $p;}$str = str_split(trim(fgets(STDIN)));$pt = str_continuity($str);$ans = 0;for ($s=0; $s<count($str); $s++){$mx = 0;//右の数$r = (count($str)-1)-($s+($pt[$s]-1));if ($ans<$pt[$s]){$ans = $pt[$s];//連続数$cntnue = $pt[$s];}if ($s>=$r){$mx = $r;}else{$mx = $s;}for ($m=1; $m<=$mx; $m++){if ($str[$s-$m]==$str[$s+($pt[$s]-1)+$m]){$tmp = $pt[$s]+($m*2);if ($ans<$tmp){$ans = $tmp;}}else{break;}}}if ($cntnue==count($str)){$ans = $ans - 1;}else if (count($str)==$ans){$ans = $ans - 2;}echo $ans . PHP_EOL;