結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー 👑 箱星箱星
提出日時 2021-07-18 20:43:58
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 910 bytes
コンパイル時間 10,636 ms
コンパイル使用メモリ 443,576 KB
実行使用メモリ 89,420 KB
最終ジャッジ日時 2024-05-09 17:14:23
合計ジャッジ時間 18,795 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
57,032 KB
testcase_01 AC 275 ms
89,420 KB
testcase_02 AC 283 ms
59,140 KB
testcase_03 AC 295 ms
53,732 KB
testcase_04 AC 293 ms
53,536 KB
testcase_05 AC 293 ms
53,732 KB
testcase_06 AC 292 ms
53,528 KB
testcase_07 AC 287 ms
53,732 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:8:22: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
    val max = a.max()!!
                     ^

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val a = Array(n) { nextInt() }
    val max = a.max()!!
    val count = Array(max + 1) { 0 }
    for (i in 0 until n) {
        count[a[i]]++
    }
    var ans = 0L
    for (i in 1..max) {
        for (j in i..max) {
            ans += count[i] * count[j] * (i % j - j % i).absoluteValue
        }
    }
    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