結果
問題 | No.158 奇妙なお使い |
ユーザー | バカらっく |
提出日時 | 2019-11-09 21:57:00 |
言語 | Kotlin (1.9.23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,830 bytes |
コンパイル時間 | 15,822 ms |
コンパイル使用メモリ | 452,832 KB |
実行使用メモリ | 85,468 KB |
最終ジャッジ日時 | 2024-09-15 04:52:32 |
合計ジャッジ時間 | 27,088 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 319 ms
51,628 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 314 ms
51,684 KB |
testcase_07 | RE | - |
testcase_08 | AC | 310 ms
51,872 KB |
testcase_09 | AC | 312 ms
51,596 KB |
testcase_10 | AC | 340 ms
52,480 KB |
testcase_11 | AC | 340 ms
52,168 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | RE | - |
testcase_16 | AC | 339 ms
52,172 KB |
testcase_17 | RE | - |
testcase_18 | AC | 572 ms
85,468 KB |
testcase_19 | AC | 323 ms
51,800 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | AC | 454 ms
59,328 KB |
testcase_23 | AC | 329 ms
52,152 KB |
testcase_24 | RE | - |
testcase_25 | WA | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | WA | - |
testcase_29 | RE | - |
testcase_30 | WA | - |
コンパイルメッセージ
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(bResult[0], bResult[1], bResult[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 }