結果

問題 No.1623 三角形の制作
ユーザー 👑 箱
提出日時 2021-07-23 21:51:19
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 1,764 ms / 2,000 ms
コード長 1,267 bytes
コンパイル時間 17,225 ms
コンパイル使用メモリ 426,180 KB
実行使用メモリ 72,720 KB
最終ジャッジ日時 2023-09-25 21:49:59
合計ジャッジ時間 36,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
53,740 KB
testcase_01 AC 310 ms
53,700 KB
testcase_02 AC 1,294 ms
67,168 KB
testcase_03 AC 1,227 ms
65,568 KB
testcase_04 AC 1,212 ms
67,876 KB
testcase_05 AC 1,764 ms
71,248 KB
testcase_06 AC 703 ms
58,732 KB
testcase_07 AC 1,244 ms
65,628 KB
testcase_08 AC 747 ms
58,600 KB
testcase_09 AC 1,171 ms
67,620 KB
testcase_10 AC 1,598 ms
72,244 KB
testcase_11 AC 1,311 ms
67,928 KB
testcase_12 AC 664 ms
61,804 KB
testcase_13 AC 700 ms
64,808 KB
testcase_14 AC 687 ms
63,504 KB
testcase_15 AC 786 ms
71,192 KB
testcase_16 AC 764 ms
71,232 KB
testcase_17 AC 791 ms
71,388 KB
testcase_18 AC 749 ms
72,720 KB
testcase_19 AC 662 ms
62,264 KB
testcase_20 AC 313 ms
53,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val r = Array(n) { nextInt() }
    val g = Array(n) { nextInt() }
    val b = Array(n) { nextInt() }
    r.sort()
    g.sort()
    b.sort()
    val cnt = LongArray(6005) { 0 }
    for (v in r) {
        cnt[v]++
    }
    for (i in 0 until 6000) {
        cnt[i + 1] += cnt[i]
    }
    var ans = 0L
    val cnt_g = LongArray(3005) { 0 }
    val cnt_b = LongArray(3005) { 0 }
    for (v in g) {
        cnt_g[v]++
    }
    for (v in b) {
        cnt_b[v]++
    }
    for (i in 1 until 3002) {
        for (j in 1 until 3002) {
            ans += cnt[i + j - 1] * cnt_g[i] * cnt_b[j]
            ans -= cnt[max(i, j) - 1] * cnt_g[i] * cnt_b[j]
        }
    }
    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