結果

問題 No.345 最小チワワ問題
ユーザー ayaaya
提出日時 2019-07-31 11:21:53
言語 PHP
(8.3.4)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 18,432 KB
実行使用メモリ 18,860 KB
最終ジャッジ日時 2023-09-18 15:54:03
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,748 KB
testcase_01 AC 14 ms
18,700 KB
testcase_02 AC 15 ms
18,636 KB
testcase_03 AC 14 ms
18,600 KB
testcase_04 AC 15 ms
18,676 KB
testcase_05 AC 14 ms
18,676 KB
testcase_06 AC 14 ms
18,676 KB
testcase_07 AC 14 ms
18,648 KB
testcase_08 AC 14 ms
18,784 KB
testcase_09 AC 15 ms
18,784 KB
testcase_10 AC 15 ms
18,652 KB
testcase_11 AC 15 ms
18,648 KB
testcase_12 AC 15 ms
18,840 KB
testcase_13 AC 15 ms
18,676 KB
testcase_14 AC 14 ms
18,680 KB
testcase_15 AC 15 ms
18,640 KB
testcase_16 AC 15 ms
18,812 KB
testcase_17 AC 16 ms
18,860 KB
testcase_18 AC 15 ms
18,744 KB
testcase_19 AC 15 ms
18,840 KB
testcase_20 AC 15 ms
18,732 KB
testcase_21 AC 14 ms
18,676 KB
testcase_22 AC 15 ms
18,600 KB
testcase_23 AC 15 ms
18,648 KB
testcase_24 AC 15 ms
18,836 KB
testcase_25 AC 15 ms
18,840 KB
testcase_26 AC 15 ms
18,852 KB
testcase_27 AC 15 ms
18,780 KB
testcase_28 AC 15 ms
18,784 KB
testcase_29 AC 15 ms
18,672 KB
testcase_30 AC 16 ms
18,656 KB
testcase_31 AC 16 ms
18,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$input=str_split(trim(fgets(STDIN)));
$cArray=array();
$wArray=array();
$wArraySection=array();
$ans=-1;
$skip=false;
//w、cそれぞれ出現するkeyを$wArray$cArrayに代入
foreach($input as $key =>$value){
  if($value=="c"){
    array_push($cArray,$key);
  }elseif($value=="w"){
    array_push($wArray,$key);
  }
}
//c1つ以上w2つ以上存在しない場合を除去
if(count($cArray)==0||count($wArray)<=1){
  $skip=true;
}
//w w間の距離を$wArraySectionに代入、keyは一文字目のwのkeyを入れる
for($i=0;$i<count($wArray)-1;$i++){
  if($skip===true){
    break;
  }
  $wArraySection[$wArray[$i]]=$wArray[$i+1]-$wArray[$i];
}

foreach( $wArraySection as $wkey =>$wSection){
  if($skip===true){
    break;
  }
  foreach($cArray as $ckey){
    if($wkey<$ckey){
      break;
    }
    $cwSection=$wSection+($wkey-$ckey)+1;
    if($ans==-1){
      $ans=$cwSection;
    }else if($ans>$cwSection){
      $ans=$cwSection;
    }
  }
}
echo $ans;
0