結果

問題 No.2078 魔抜けなパープル
ユーザー 👑 箱
提出日時 2022-09-25 21:07:49
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 15,469 ms
コンパイル使用メモリ 424,884 KB
実行使用メモリ 54,836 KB
最終ジャッジ日時 2023-08-24 01:54:36
合計ジャッジ時間 16,076 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 276 ms
52,972 KB
testcase_01 AC 298 ms
52,816 KB
testcase_02 AC 296 ms
54,836 KB
testcase_03 AC 299 ms
52,632 KB
testcase_04 AC 291 ms
54,608 KB
testcase_05 AC 290 ms
53,004 KB
testcase_06 AC 295 ms
52,684 KB
testcase_07 AC 291 ms
52,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val numCases = nextInt()
    case@ for (_i in 0 until numCases) {
        val x = nextInt()
        val a = nextInt()
        var ans = Long.MAX_VALUE
        for (m in 1..a) {
            val n1 = a % m
            val n2 = m - n1
            val v = m.toLong() * x + n1.toLong() * (a / m + 1) * (a / m + 1) + n2.toLong() * (a / m) * (a / m)
            ans = minOf(ans, v)
        }
        println(ans)
    }
}

fun main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

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()
// endregion
0