結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー はむ吉🐹
提出日時 2016-02-27 17:19:50
言語 Scala(Beta)
(3.8.2)
コンパイル:
scalac _filename_
実行:
/usr/bin/scala_run _class_
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 609 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,386 ms
コンパイル使用メモリ 259,532 KB
実行使用メモリ 54,760 KB
最終ジャッジ日時 2026-03-09 14:40:22
合計ジャッジ時間 22,523 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

object Main {

    def solve(s: String): Int = {
        val n = s.length
        var answer, w1, w2 = Int.MaxValue
        for (idx <- (n - 1) to 0 by -1) {
            if (s(idx) == 'w') {
                w2 = w1
                w1 = idx
            } else if (s(idx) == 'c' && w2 < Int.MaxValue) {
                answer = scala.math.min(answer, w2 - idx + 1)
            }
        }
        if (answer < Int.MaxValue) {
            return answer
        } else {
            return -1
        }
    }

    def main(args: Array[String]): Unit = {
        println(solve(scala.io.StdIn.readLine()))
    }

}
0