結果

問題 No.1594 Three Classes
ユーザー 👑 箱星箱星
提出日時 2021-07-09 22:34:08
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 15,511 ms
コンパイル使用メモリ 445,664 KB
実行使用メモリ 50,188 KB
最終ジャッジ日時 2024-04-28 00:32:19
合計ジャッジ時間 21,530 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 350 ms
49,872 KB
testcase_01 AC 282 ms
49,728 KB
testcase_02 AC 284 ms
49,692 KB
testcase_03 AC 291 ms
49,824 KB
testcase_04 AC 354 ms
49,936 KB
testcase_05 AC 343 ms
50,020 KB
testcase_06 AC 293 ms
50,004 KB
testcase_07 AC 294 ms
50,036 KB
testcase_08 AC 345 ms
49,940 KB
testcase_09 AC 343 ms
50,188 KB
testcase_10 AC 345 ms
49,908 KB
testcase_11 AC 343 ms
49,892 KB
testcase_12 AC 343 ms
50,160 KB
testcase_13 AC 280 ms
49,764 KB
testcase_14 AC 306 ms
49,852 KB
testcase_15 AC 295 ms
49,904 KB
testcase_16 AC 310 ms
49,956 KB
testcase_17 AC 308 ms
49,832 KB
testcase_18 AC 281 ms
49,856 KB
testcase_19 AC 290 ms
49,696 KB
testcase_20 AC 280 ms
49,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val e = Array(n) { nextInt() }
    val pow = Array(n) { 3 }.fold(1, Int::times)
    for (i in 0 until pow) {
        var pa = 0
        var pb = 0
        var pc = 0
        var k = i
        for (j in 0 until n) {
            if (k % 3 == 0) {
                pa += e[j]
            } else if (k % 3 == 1) {
                pb += e[j]
            } else {
                pc += e[j]
            }
            k /= 3
        }
        if (pa == pb && pb == pc) {
            println("Yes")
            return
        }
    }
    println("No")
}

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