結果
問題 | No.158 奇妙なお使い |
ユーザー | バカらっく |
提出日時 | 2019-11-09 21:59:01 |
言語 | Kotlin (1.9.23) |
結果 |
AC
|
実行時間 | 1,525 ms / 5,000 ms |
コード長 | 2,830 bytes |
コンパイル時間 | 15,351 ms |
コンパイル使用メモリ | 455,736 KB |
実行使用メモリ | 133,916 KB |
最終ジャッジ日時 | 2024-09-15 04:53:25 |
合計ジャッジ時間 | 28,938 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 321 ms
52,104 KB |
testcase_01 | AC | 348 ms
52,548 KB |
testcase_02 | AC | 322 ms
51,976 KB |
testcase_03 | AC | 312 ms
51,688 KB |
testcase_04 | AC | 1,525 ms
133,916 KB |
testcase_05 | AC | 307 ms
51,564 KB |
testcase_06 | AC | 303 ms
51,612 KB |
testcase_07 | AC | 307 ms
51,664 KB |
testcase_08 | AC | 311 ms
51,568 KB |
testcase_09 | AC | 311 ms
51,636 KB |
testcase_10 | AC | 338 ms
52,272 KB |
testcase_11 | AC | 340 ms
52,196 KB |
testcase_12 | AC | 309 ms
51,716 KB |
testcase_13 | AC | 316 ms
51,620 KB |
testcase_14 | AC | 349 ms
52,488 KB |
testcase_15 | AC | 428 ms
61,268 KB |
testcase_16 | AC | 355 ms
52,360 KB |
testcase_17 | AC | 460 ms
64,132 KB |
testcase_18 | AC | 789 ms
100,428 KB |
testcase_19 | AC | 333 ms
52,120 KB |
testcase_20 | AC | 343 ms
52,516 KB |
testcase_21 | AC | 474 ms
65,576 KB |
testcase_22 | AC | 466 ms
59,376 KB |
testcase_23 | AC | 336 ms
52,208 KB |
testcase_24 | AC | 332 ms
52,104 KB |
testcase_25 | AC | 307 ms
51,756 KB |
testcase_26 | AC | 341 ms
52,264 KB |
testcase_27 | AC | 314 ms
51,744 KB |
testcase_28 | AC | 428 ms
60,900 KB |
testcase_29 | AC | 331 ms
52,192 KB |
testcase_30 | AC | 443 ms
61,376 KB |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used fun main(arr:Array<String>) { ^
ソースコード
import java.util.* fun main(arr:Array<String>) { val a = readLine()!!.split(" ").map { it.toInt() } bRequire = readLine()!!.toInt() bReturn = readLine()!!.split(" ").map { it.toInt() }.toTypedArray() cRequire = readLine()!!.toInt() cReturn = readLine()!!.split(" ").map { it.toInt() }.toTypedArray() work.push(Task(a[0], a[1], a[2])) while (work.isNotEmpty()) { val task = work.pop() getAns(task.rem1000, task.rem100, task.rem1) } val ans = getAns(a[0], a[1], a[2]) println(ans) } var bRequire = 0 var cRequire = 0 var bReturn = arrayOf(0,0,0) var cReturn = arrayOf(0,0,0) var work = Stack<Task>() val dic = mutableMapOf<Int, MutableMap<Int, MutableMap<Int, Int>>>() fun getAns(rem1000: Int, rem100: Int, rem1: Int):Int { if(!dic.containsKey(rem1000)) { dic[rem1000] = mutableMapOf() } if(!dic[rem1000]!!.containsKey(rem100)) { dic[rem1000]!![rem100] = mutableMapOf() } dic[rem1000]!![rem100]!![rem1]?.let { return it } val bResult = doOtsukai(bRequire, bReturn, rem1000, rem100, rem1) var bRet = 0 if(bResult.isNotEmpty()) { val task = Task(bResult[0], bResult[1], bResult[2]) if(taskInDic(task)) { bRet = getAns(bResult[0], bResult[1], bResult[2]) + 1 } else { work.push(Task(rem1000, rem100, rem1)) work.push(task) return 0 } } val cResult = doOtsukai(cRequire, cReturn, rem1000, rem100, rem1) var cRet = 0 if(cResult.isNotEmpty()) { val task = Task(cResult[0], cResult[1], cResult[2]) if(taskInDic(task)) { cRet = getAns(cResult[0], cResult[1], cResult[2]) + 1 } else { work.push(Task(rem1000, rem100, rem1)) work.push(task) return 0 } } val ans = Math.max(bRet, cRet) dic[rem1000]!![rem100]!![rem1] = ans return ans } class Task(val rem1000: Int, val rem100: Int, val rem1: Int) fun taskInDic(task: Task):Boolean { if(!dic.containsKey(task.rem1000)) { return false } if(!dic[task.rem1000]!!.containsKey(task.rem100)) { return false } return dic[task.rem1000]!![task.rem100]!!.containsKey(task.rem1) } fun doOtsukai(require:Int, otusri:Array<Int>, rem1000:Int, rem100:Int, rem1:Int):Array<Int> { if(require > rem1000 * 1000 + rem100 * 100 + rem1) { return emptyArray() } var remain = require var r1000 = rem1000 while (remain >= 1000 && r1000 > 0) { r1000-- remain -= 1000 } var r100 = rem100 while (remain >= 100 && r100 > 0) { r100-- remain -= 100 } if(remain > rem1) { return emptyArray() } val ret = arrayOf(r1000 + otusri[0], r100 + otusri[1], rem1 - remain + otusri[2] ) return ret }