結果

問題 No.1702 count good string
ユーザー 👑 箱
提出日時 2021-10-08 22:59:15
言語 Kotlin
(1.9.23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,093 bytes
コンパイル時間 20,895 ms
コンパイル使用メモリ 435,040 KB
実行使用メモリ 148,124 KB
最終ジャッジ日時 2023-09-30 12:16:10
合計ジャッジ時間 70,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 323 ms
59,272 KB
testcase_01 AC 320 ms
59,640 KB
testcase_02 AC 323 ms
57,472 KB
testcase_03 AC 334 ms
57,224 KB
testcase_04 AC 329 ms
59,164 KB
testcase_05 AC 330 ms
59,180 KB
testcase_06 AC 328 ms
59,284 KB
testcase_07 AC 331 ms
59,300 KB
testcase_08 AC 326 ms
59,408 KB
testcase_09 AC 325 ms
57,396 KB
testcase_10 AC 325 ms
59,532 KB
testcase_11 AC 326 ms
57,476 KB
testcase_12 AC 327 ms
59,480 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 375 ms
57,988 KB
testcase_24 AC 379 ms
59,964 KB
testcase_25 AC 375 ms
59,956 KB
testcase_26 AC 376 ms
58,032 KB
testcase_27 AC 381 ms
59,944 KB
testcase_28 AC 392 ms
59,936 KB
testcase_29 AC 387 ms
58,164 KB
testcase_30 AC 383 ms
61,728 KB
testcase_31 AC 383 ms
57,836 KB
testcase_32 AC 383 ms
60,060 KB
testcase_33 AC 1,929 ms
148,124 KB
testcase_34 AC 1,948 ms
144,360 KB
testcase_35 AC 1,921 ms
146,576 KB
testcase_36 AC 1,923 ms
146,272 KB
testcase_37 AC 1,914 ms
145,900 KB
testcase_38 AC 1,914 ms
146,020 KB
testcase_39 AC 1,925 ms
144,228 KB
testcase_40 AC 1,934 ms
146,120 KB
testcase_41 AC 1,926 ms
144,228 KB
testcase_42 AC 1,932 ms
144,412 KB
testcase_43 TLE -
testcase_44 TLE -
testcase_45 AC 319 ms
57,276 KB
testcase_46 AC 320 ms
57,240 KB
testcase_47 AC 331 ms
59,156 KB
testcase_48 AC 319 ms
58,980 KB
testcase_49 AC 323 ms
59,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun helper(n: Int, s: String, t: String): ModInt {
    val dp = Array(n + 1) { Array(t.length + 1) { ModInt(0) } }
    dp[0][0] = ModInt(1)
    for (i in 0 until n) {
        for (j in 0 until t.length + 1) {
            dp[i + 1][j] += dp[i][j]
        }
        for (j in t.indices) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] += dp[i][j]
            }
        }
    }
    return dp[n][t.length]
}

fun PrintWriter.solve() {
    val n = nextInt()
    val s = nextLine()
    var ans = ModInt(0)
    val lst = mutableListOf("yukicoder")
    for (i in 0 until 9) {
        val t = "yukicoder".toCharArray().withIndex().map { if (it.index == i) '?' else it.value }.joinToString("")
        lst.add(t)
    }
    for (t in lst) {
        ans += helper(n, s, t)
    }
    println(ans)
}

// region ModInt
class ModInt(x: Long) {
    companion object {
        const val MOD = 1000000007L
        //const val MOD = 998244353L
    }

    constructor(y: Int) : this(y.toLong())

    val x = (x % MOD + MOD) % MOD

    operator fun plus(other: ModInt): ModInt {
        return ModInt(x + other.x)
    }

    operator fun minus(other: ModInt): ModInt {
        return ModInt(x - other.x)
    }

    operator fun times(other: ModInt): ModInt {
        return ModInt(x * other.x)
    }

    operator fun div(other: ModInt): ModInt {
        return this * other.inv()
    }

    fun pow(exp: Long): ModInt {
        if (exp == 0L) return ModInt(1L)
        var a = pow(exp shr 1)
        a *= a
        if (exp and 1L == 0L) return a
        return this * a
    }

    fun inv(): ModInt {
        return this.pow(MOD - 2)
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ModInt

        if (x != other.x) return false

        return true
    }

    override fun hashCode(): Int {
        return x.hashCode()
    }

    override fun toString(): String {
        return "$x"
    }
}

fun Long.toModInt(): ModInt {
    return ModInt(this)
}

fun Int.toModInt(): ModInt {
    return ModInt(this)
}

fun binomSimple(n: Long, k: Long): ModInt {
    var numer = ModInt(1)
    var denom = ModInt(1)
    for (i in 0 until k) {
        numer *= ModInt(n - i)
        denom *= ModInt(k - i)
    }
    return numer / denom
}
// endregion

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", 1.shl(26))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

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()
// endregion
0