結果

問題 No.2260 Adic Sum
ユーザー 👑 箱
提出日時 2023-04-07 21:48:12
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 875 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 15,027 ms
コンパイル使用メモリ 443,196 KB
実行使用メモリ 101,408 KB
最終ジャッジ日時 2024-04-15 23:53:12
合計ジャッジ時間 32,531 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 281 ms
58,596 KB
testcase_01 AC 283 ms
58,520 KB
testcase_02 AC 284 ms
58,604 KB
testcase_03 AC 283 ms
58,492 KB
testcase_04 AC 279 ms
58,628 KB
testcase_05 AC 284 ms
58,700 KB
testcase_06 AC 288 ms
58,664 KB
testcase_07 AC 280 ms
58,444 KB
testcase_08 AC 318 ms
58,776 KB
testcase_09 AC 295 ms
58,528 KB
testcase_10 AC 312 ms
58,764 KB
testcase_11 AC 291 ms
58,628 KB
testcase_12 AC 327 ms
58,920 KB
testcase_13 AC 311 ms
58,468 KB
testcase_14 AC 447 ms
67,640 KB
testcase_15 AC 463 ms
72,020 KB
testcase_16 AC 441 ms
65,532 KB
testcase_17 AC 469 ms
71,792 KB
testcase_18 AC 791 ms
101,408 KB
testcase_19 AC 813 ms
100,332 KB
testcase_20 AC 681 ms
97,176 KB
testcase_21 AC 678 ms
97,196 KB
testcase_22 AC 661 ms
97,288 KB
testcase_23 AC 624 ms
93,076 KB
testcase_24 AC 728 ms
95,304 KB
testcase_25 AC 511 ms
77,692 KB
testcase_26 AC 491 ms
78,024 KB
testcase_27 AC 502 ms
77,980 KB
testcase_28 AC 493 ms
77,940 KB
testcase_29 AC 497 ms
77,784 KB
testcase_30 AC 525 ms
81,968 KB
testcase_31 AC 771 ms
95,112 KB
testcase_32 AC 795 ms
95,296 KB
testcase_33 AC 524 ms
84,184 KB
testcase_34 AC 668 ms
97,376 KB
testcase_35 AC 875 ms
97,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val p = nextLong()
    val a = Array(n) { nextLong() }
    var ans = 0L
    var pow = p
    while (true) {
        val counter = mutableMapOf<Long, Long>()
        for (v in a) {
            counter[v % pow] = (counter[v % pow] ?: 0) + 1
        }
        for (v in counter.values) {
            ans += v * (v - 1) / 2
        }
        pow *= p
        if (pow > 1000000000L) break
    }
    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