結果
問題 | No.1029 JJOOII 3 |
ユーザー | yakamoto |
提出日時 | 2020-04-24 02:15:17 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 648 ms / 2,000 ms |
コード長 | 3,211 bytes |
コンパイル時間 | 17,126 ms |
コンパイル使用メモリ | 461,960 KB |
実行使用メモリ | 52,776 KB |
最終ジャッジ日時 | 2024-10-14 11:45:09 |
合計ジャッジ時間 | 36,056 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 287 ms
49,872 KB |
testcase_01 | AC | 288 ms
49,900 KB |
testcase_02 | AC | 289 ms
49,936 KB |
testcase_03 | AC | 349 ms
50,764 KB |
testcase_04 | AC | 386 ms
51,912 KB |
testcase_05 | AC | 571 ms
52,600 KB |
testcase_06 | AC | 512 ms
51,688 KB |
testcase_07 | AC | 548 ms
52,300 KB |
testcase_08 | AC | 590 ms
52,296 KB |
testcase_09 | AC | 530 ms
52,164 KB |
testcase_10 | AC | 544 ms
52,228 KB |
testcase_11 | AC | 580 ms
52,672 KB |
testcase_12 | AC | 480 ms
51,652 KB |
testcase_13 | AC | 580 ms
52,684 KB |
testcase_14 | AC | 581 ms
52,552 KB |
testcase_15 | AC | 397 ms
51,828 KB |
testcase_16 | AC | 321 ms
51,932 KB |
testcase_17 | AC | 505 ms
52,336 KB |
testcase_18 | AC | 564 ms
52,508 KB |
testcase_19 | AC | 292 ms
50,064 KB |
testcase_20 | AC | 314 ms
49,964 KB |
testcase_21 | AC | 312 ms
49,748 KB |
testcase_22 | AC | 319 ms
49,864 KB |
testcase_23 | AC | 311 ms
50,068 KB |
testcase_24 | AC | 312 ms
49,968 KB |
testcase_25 | AC | 320 ms
49,948 KB |
testcase_26 | AC | 315 ms
50,188 KB |
testcase_27 | AC | 314 ms
50,152 KB |
testcase_28 | AC | 312 ms
49,868 KB |
testcase_29 | AC | 315 ms
50,064 KB |
testcase_30 | AC | 312 ms
50,096 KB |
testcase_31 | AC | 314 ms
50,028 KB |
testcase_32 | AC | 636 ms
52,716 KB |
testcase_33 | AC | 643 ms
52,676 KB |
testcase_34 | AC | 638 ms
52,680 KB |
testcase_35 | AC | 639 ms
52,772 KB |
testcase_36 | AC | 648 ms
52,776 KB |
testcase_37 | AC | 287 ms
49,892 KB |
testcase_38 | AC | 291 ms
49,776 KB |
testcase_39 | AC | 290 ms
50,004 KB |
testcase_40 | AC | 290 ms
49,732 KB |
ソースコード
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 data class Entry(val s: String, val c: Long) data class Edge(val v: Int, val weight: Long) val INF = 1e18.toLong() class Solver(stream: InputStream, private val out: java.io.PrintWriter) { fun solve() { val N = ni() val K = ni() val E = Array(N){Entry(ns(), nl())} val JOI = "JOI" val cnt = Array(N){i -> Array(3){j -> E[i].s.count{ it == JOI[j]}} } fun calcEnd(s: String, start: Int): Int { var cur = start for (i in 0 until s.length) { if (cur == 3 * K) return cur if (s[i] == JOI[cur / K]) cur++ } return cur } val D = LongArray(3 * K + 1){INF} D[0] = 0 for (u in 0 until 3 * K) { if (D[u] == INF) continue for ((i, e) in E.withIndex()) { val v = if (K - u % K > 100) { u + cnt[i][u / K] } else { calcEnd(e.s, u) } if (v > u) { if (D[v] > D[u] + e.c) { D[v] = D[u] + e.c } } } } debug(D) val cost = D[3 * K] if (cost == INF) out.println(-1) else out.println(cost) } 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<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() }