結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー norioc
提出日時 2016-02-27 08:58:05
言語 Scala(Beta)
(3.8.2)
コンパイル:
scalac _filename_
実行:
/usr/bin/scala_run _class_
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 454 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,753 ms
コンパイル使用メモリ 269,072 KB
実行使用メモリ 59,456 KB
最終ジャッジ日時 2026-03-09 14:39:44
合計ジャッジ時間 24,097 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math._

object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val s = sc.next

    val reg = "c.*?w.*?w".r
    var ans = Integer.MAX_VALUE
    for (i <- 0 to s.length-1 if s(i) == 'c') {
      reg.findFirstIn(s.substring(i)) match {
        case Some(v) => ans = min(ans, v.length)
        case _ =>
      }
    }

    if (ans == Integer.MAX_VALUE)
      println(-1)
    else
      println(ans)
  }
}
0