結果

問題 No.1159 Sashiming String
ユーザー 👑 箱星箱星
提出日時 2020-08-19 17:50:43
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 13,325 ms
コンパイル使用メモリ 436,648 KB
実行使用メモリ 71,960 KB
最終ジャッジ日時 2024-04-20 09:40:53
合計ジャッジ時間 19,791 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
56,880 KB
testcase_01 AC 318 ms
56,916 KB
testcase_02 AC 440 ms
65,980 KB
testcase_03 AC 444 ms
69,924 KB
testcase_04 AC 381 ms
65,392 KB
testcase_05 AC 439 ms
69,896 KB
testcase_06 AC 379 ms
65,420 KB
testcase_07 AC 438 ms
67,880 KB
testcase_08 AC 450 ms
71,940 KB
testcase_09 AC 456 ms
71,960 KB
testcase_10 AC 302 ms
54,128 KB
testcase_11 AC 316 ms
56,628 KB
testcase_12 AC 317 ms
56,904 KB
testcase_13 AC 316 ms
56,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val s = sc.nextLine()
    val n = s.length
    val num_ing = Array(n) { 0 }
    for (i in n - 3 downTo 0) {
        if (s.substring(i..i + 2) == "ing") {
            num_ing[i]++
        }
        if (i < n - 1) {
            num_ing[i] += num_ing[i + 1]
        }
    }
    var ans = 0L
    for (i in 0 until n) {
        if (s[i] == 'S') {
            ans += num_ing[i]
        }
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0