結果

問題 No.1343 Dividing Digit
ユーザー 👑 箱星箱星
提出日時 2021-01-16 14:22:29
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 439 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 14,057 ms
コンパイル使用メモリ 447,560 KB
実行使用メモリ 62,540 KB
最終ジャッジ日時 2024-05-05 16:40:27
合計ジャッジ時間 22,424 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
53,232 KB
testcase_01 AC 273 ms
53,212 KB
testcase_02 AC 262 ms
53,180 KB
testcase_03 AC 419 ms
61,704 KB
testcase_04 AC 326 ms
54,312 KB
testcase_05 AC 380 ms
56,144 KB
testcase_06 AC 344 ms
55,020 KB
testcase_07 AC 388 ms
56,960 KB
testcase_08 AC 402 ms
60,488 KB
testcase_09 AC 421 ms
61,512 KB
testcase_10 AC 334 ms
54,720 KB
testcase_11 AC 391 ms
56,988 KB
testcase_12 AC 413 ms
60,568 KB
testcase_13 AC 431 ms
60,008 KB
testcase_14 AC 329 ms
54,636 KB
testcase_15 AC 375 ms
56,492 KB
testcase_16 AC 340 ms
54,740 KB
testcase_17 AC 417 ms
61,292 KB
testcase_18 AC 417 ms
62,044 KB
testcase_19 AC 413 ms
59,484 KB
testcase_20 AC 388 ms
57,428 KB
testcase_21 AC 418 ms
61,112 KB
testcase_22 AC 431 ms
60,760 KB
testcase_23 AC 439 ms
62,540 KB
testcase_24 AC 395 ms
59,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val k = nextInt()
    val a = Array(n) { nextInt() }
    val r = a.sum().toLong()
    var pow = 1L
    var ans = 0L
    for (i in n - 1 downTo 0) {
        ans += a[i] * pow
        ans %= r
        pow *= k
        pow %= r
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve()
    writer.flush()
}

// 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