結果

問題 No.1111 コード進行
ユーザー 👑 箱星箱星
提出日時 2020-07-10 21:49:49
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,620 ms / 2,000 ms
コード長 3,584 bytes
コンパイル時間 18,516 ms
コンパイル使用メモリ 462,460 KB
実行使用メモリ 117,828 KB
最終ジャッジ日時 2024-04-19 16:48:33
合計ジャッジ時間 40,014 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
50,188 KB
testcase_01 AC 274 ms
50,056 KB
testcase_02 AC 272 ms
50,000 KB
testcase_03 AC 272 ms
49,976 KB
testcase_04 AC 271 ms
49,884 KB
testcase_05 AC 342 ms
63,184 KB
testcase_06 AC 370 ms
85,720 KB
testcase_07 AC 341 ms
66,712 KB
testcase_08 AC 315 ms
59,576 KB
testcase_09 AC 348 ms
67,456 KB
testcase_10 AC 330 ms
83,196 KB
testcase_11 AC 317 ms
60,244 KB
testcase_12 AC 358 ms
84,708 KB
testcase_13 AC 345 ms
72,288 KB
testcase_14 AC 373 ms
86,004 KB
testcase_15 AC 330 ms
55,864 KB
testcase_16 AC 370 ms
84,352 KB
testcase_17 AC 331 ms
84,064 KB
testcase_18 AC 340 ms
57,212 KB
testcase_19 AC 312 ms
54,988 KB
testcase_20 AC 342 ms
64,468 KB
testcase_21 AC 277 ms
50,984 KB
testcase_22 AC 362 ms
85,616 KB
testcase_23 AC 339 ms
71,228 KB
testcase_24 AC 350 ms
77,328 KB
testcase_25 AC 382 ms
88,968 KB
testcase_26 AC 373 ms
84,132 KB
testcase_27 AC 303 ms
57,568 KB
testcase_28 AC 682 ms
90,688 KB
testcase_29 AC 461 ms
85,536 KB
testcase_30 AC 614 ms
91,020 KB
testcase_31 AC 358 ms
89,260 KB
testcase_32 AC 524 ms
86,528 KB
testcase_33 AC 575 ms
90,248 KB
testcase_34 AC 582 ms
89,392 KB
testcase_35 AC 594 ms
87,520 KB
testcase_36 AC 852 ms
90,620 KB
testcase_37 AC 416 ms
84,636 KB
testcase_38 AC 430 ms
85,092 KB
testcase_39 AC 748 ms
90,892 KB
testcase_40 AC 784 ms
90,228 KB
testcase_41 AC 708 ms
90,208 KB
testcase_42 AC 495 ms
86,468 KB
testcase_43 AC 523 ms
88,000 KB
testcase_44 AC 391 ms
85,996 KB
testcase_45 AC 581 ms
88,012 KB
testcase_46 AC 313 ms
58,412 KB
testcase_47 AC 1,620 ms
117,828 KB
testcase_48 AC 325 ms
60,124 KB
testcase_49 AC 320 ms
58,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// ModInt
// region
class ModInt(x: Long) {

    companion object {
        const val MOD = 1000000007L
        //const val MOD = 998244353L
    }

    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"
    }

}

val fac = mutableListOf<ModInt>()
val invfac = mutableListOf<ModInt>()

fun fact(n: Long, b: Boolean): ModInt {
    if (fac.count() == 0) {
        fac.add(ModInt(1))
        invfac.add(ModInt(1))
    }
    while (fac.count() <= n) {
        fac.add(fac.last() * ModInt(fac.count().toLong()))
        invfac.add(fac.last().inv())
    }
    return if (b) {
        fac[n.toInt()]
    } else {
        invfac[n.toInt()]
    }
}

fun comb(n: Long, k: Long): ModInt {
    return fact(n, true) * fact(k, false) * fact(n - k, false)
}

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

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val k = sc.nextInt()
    val code = mutableListOf<Triple<Int, Int, Int>>()
    val next = Array(300) { mutableListOf<Pair<Int, Int>>() }
    for (i in 0 until m) {
        val p = sc.nextInt() - 1
        val q = sc.nextInt() - 1
        val c = sc.nextInt()
        code.add(Triple(p, q, c))
        next[p].add(q to c)
    }
    var dp = Array(300) { Array(k + 1) { ModInt(0) } }
    for (i in 0 until 300) {
        dp[i][0] = ModInt(1)
    }
    for (i in 1 until n) {
        val newdp = Array(300) { Array(k + 1) { ModInt(0) } }
        for (j in 0 until 300) {
            for (s in 0..k) {
                for ((x, c) in next[j]) {
                    if (s + c > k) continue
                    newdp[x][s + c] += dp[j][s]
                }
            }
        }
        dp = newdp
    }
    var sum = ModInt(0)
    for (i in 0 until 300) {
        sum += dp[i][k]
    }
    println(sum)
}

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