結果

問題 No.118 門松列(2)
ユーザー バカらっく
提出日時 2019-10-02 03:08:04
言語 Kotlin
(2.1.0)
結果
AC  
実行時間 585 ms / 5,000 ms
コード長 908 bytes
コンパイル時間 11,692 ms
コンパイル使用メモリ 447,776 KB
実行使用メモリ 71,456 KB
最終ジャッジ日時 2024-10-03 05:50:28
合計ジャッジ時間 25,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:2:9: warning: variable 'itemCount' is never used
    val itemCount = readLine()!!.toInt()
        ^

ソースコード

diff #

fun main(arr:Array<String>) {
    val itemCount = readLine()!!.toInt()
    val items = readLine()!!.split(" ").map { it.toInt() }.let { a-> a.toSet().sorted().map { b-> b to a.count { it == b } } }.toMap()
    val keys = items.keys.toList()
    val count = items.keys.map { 0 }.toTypedArray()
    val mod = 1000000000 + 7
    for(i in keys.indices) {
        if(i == 0) {
            count[0] = items[keys[0]]!!
        } else {
            count[i] = count[i-1] + items[keys[i]]!!
        }
    }

    var ans = 0L
    for(i in (0..keys.lastIndex - 2)) {
        for(j in (i+1..keys.lastIndex - 1)) {
            val remain = (count.last() - count[j]).toLong()
            var ptn = items[keys[i]]!!.toLong() * items[keys[j]]!!.toLong()
            ptn = ptn % mod
            ptn *= remain
            ptn = ptn % mod
            ans += ptn
            ans = ans % mod
        }
    }
    println(ans)

}

0