結果

問題 No.1111 コード進行
ユーザー 👑 箱星箱星
提出日時 2020-07-10 21:46:09
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 3,518 bytes
コンパイル時間 15,611 ms
コンパイル使用メモリ 453,576 KB
実行使用メモリ 108,208 KB
最終ジャッジ日時 2024-04-19 20:51:59
合計ジャッジ時間 30,432 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 259 ms
53,400 KB
testcase_01 AC 262 ms
85,860 KB
testcase_02 AC 269 ms
54,368 KB
testcase_03 AC 262 ms
49,784 KB
testcase_04 AC 265 ms
49,768 KB
testcase_05 AC 324 ms
63,956 KB
testcase_06 AC 343 ms
70,544 KB
testcase_07 AC 350 ms
67,764 KB
testcase_08 AC 341 ms
56,544 KB
testcase_09 AC 334 ms
64,640 KB
testcase_10 AC 370 ms
76,364 KB
testcase_11 AC 320 ms
56,828 KB
testcase_12 AC 337 ms
71,640 KB
testcase_13 AC 351 ms
65,040 KB
testcase_14 AC 393 ms
105,424 KB
testcase_15 AC 322 ms
55,452 KB
testcase_16 AC 389 ms
74,420 KB
testcase_17 AC 338 ms
77,144 KB
testcase_18 AC 319 ms
56,980 KB
testcase_19 AC 294 ms
55,836 KB
testcase_20 AC 330 ms
62,688 KB
testcase_21 AC 271 ms
50,732 KB
testcase_22 AC 374 ms
108,208 KB
testcase_23 AC 308 ms
62,644 KB
testcase_24 AC 333 ms
67,488 KB
testcase_25 AC 416 ms
108,192 KB
testcase_26 AC 339 ms
74,244 KB
testcase_27 AC 329 ms
57,296 KB
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
    }
    val dp = Array(n+1) { Array(300) { Array(k + 1) { ModInt(0) } } }
    for (i in 0 until 300) {
        dp[1][i][0] = ModInt(1)
    }
    for (i in 1 until n) {
        for (j in 0 until 300) {
            for (s in 0..k) {
                for ((x, c) in next[j]) {
                    if (s + c > k) continue
                    dp[i+1][x][s+c] += dp[i][j][s]
                }
            }
        }
    }
    var sum = ModInt(0)
    for (i in 0 until 300) {
        sum += dp[n][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