結果

問題 No.1111 コード進行
ユーザー yakamotoyakamoto
提出日時 2020-07-10 22:06:07
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 3,304 bytes
コンパイル時間 18,522 ms
コンパイル使用メモリ 431,920 KB
実行使用メモリ 57,564 KB
最終ジャッジ日時 2023-08-01 18:04:18
合計ジャッジ時間 34,505 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
53,816 KB
testcase_01 AC 274 ms
54,064 KB
testcase_02 AC 277 ms
53,580 KB
testcase_03 AC 278 ms
53,788 KB
testcase_04 AC 273 ms
53,768 KB
testcase_05 AC 312 ms
57,128 KB
testcase_06 AC 327 ms
56,928 KB
testcase_07 AC 351 ms
56,664 KB
testcase_08 AC 345 ms
56,584 KB
testcase_09 AC 374 ms
57,548 KB
testcase_10 AC 350 ms
57,064 KB
testcase_11 AC 346 ms
54,608 KB
testcase_12 AC 348 ms
57,180 KB
testcase_13 AC 354 ms
57,416 KB
testcase_14 AC 375 ms
57,260 KB
testcase_15 AC 343 ms
54,392 KB
testcase_16 AC 373 ms
57,220 KB
testcase_17 AC 308 ms
56,348 KB
testcase_18 AC 310 ms
54,496 KB
testcase_19 AC 272 ms
55,816 KB
testcase_20 AC 338 ms
57,524 KB
testcase_21 AC 292 ms
53,976 KB
testcase_22 AC 338 ms
57,564 KB
testcase_23 AC 322 ms
56,512 KB
testcase_24 AC 340 ms
56,612 KB
testcase_25 AC 368 ms
57,200 KB
testcase_26 AC 360 ms
56,512 KB
testcase_27 AC 344 ms
56,440 KB
testcase_28 AC 347 ms
56,952 KB
testcase_29 AC 321 ms
56,524 KB
testcase_30 AC 350 ms
57,188 KB
testcase_31 AC 317 ms
56,860 KB
testcase_32 AC 400 ms
56,944 KB
testcase_33 AC 404 ms
57,552 KB
testcase_34 AC 332 ms
57,140 KB
testcase_35 AC 335 ms
56,804 KB
testcase_36 AC 480 ms
57,460 KB
testcase_37 AC 368 ms
56,648 KB
testcase_38 AC 353 ms
56,672 KB
testcase_39 AC 408 ms
57,468 KB
testcase_40 AC 423 ms
57,268 KB
testcase_41 AC 357 ms
56,996 KB
testcase_42 AC 387 ms
56,512 KB
testcase_43 AC 379 ms
56,648 KB
testcase_44 AC 343 ms
56,892 KB
testcase_45 AC 341 ms
57,100 KB
testcase_46 AC 325 ms
54,136 KB
testcase_47 AC 561 ms
57,236 KB
testcase_48 AC 325 ms
54,332 KB
testcase_49 AC 329 ms
54,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

data class Trans(val p: Int, val q: Int, val c: Int)
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val M = ni()
    val K = ni()
    val T = Array(M){Trans(ni() - 1, ni() - 1, ni())}
    val map = Array(300){mutableListOf<Trans>()}
    for (t in T) {
      map[t.p].add(t)
    }
    var best = Array(K + 1){LongArray(300)}
    var next = Array(K + 1){LongArray(300)}
    for (i in 0 until 300) {
      best[0][i] = 1
    }

    for (times in 0 until N - 1) {
      for (k in 0 .. K) {
        Arrays.fill(next[k], 0)
      }
      for (k in 0 .. K) {
        for (p in 0 until 300) {
          for (i in 0 until map[p].size) {
            val t = map[p][i]
            if (k + t.c <= K) {
              next[k + t.c][t.q] += best[k][p]
              next[k + t.c][t.q] %= MOD
            }
          }
        }
      }
      debug{"$times"}
      debugDim(next)
      val tmp = best
      best = next
      next = tmp
    }
    out.println(best[K].sum() % MOD)
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}
0