結果

問題 No.1594 Three Classes
ユーザー 👑 箱
提出日時 2021-07-09 22:34:08
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 14,135 ms
コンパイル使用メモリ 420,672 KB
実行使用メモリ 50,644 KB
最終ジャッジ日時 2023-08-10 06:54:59
合計ジャッジ時間 21,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 332 ms
50,360 KB
testcase_01 AC 254 ms
50,216 KB
testcase_02 AC 262 ms
50,504 KB
testcase_03 AC 273 ms
50,380 KB
testcase_04 AC 330 ms
50,220 KB
testcase_05 AC 321 ms
50,112 KB
testcase_06 AC 279 ms
50,472 KB
testcase_07 AC 281 ms
50,644 KB
testcase_08 AC 339 ms
50,516 KB
testcase_09 AC 334 ms
50,360 KB
testcase_10 AC 328 ms
50,372 KB
testcase_11 AC 330 ms
50,212 KB
testcase_12 AC 328 ms
50,344 KB
testcase_13 AC 273 ms
50,200 KB
testcase_14 AC 291 ms
50,524 KB
testcase_15 AC 278 ms
50,328 KB
testcase_16 AC 275 ms
50,256 KB
testcase_17 AC 277 ms
50,248 KB
testcase_18 AC 271 ms
50,252 KB
testcase_19 AC 271 ms
50,452 KB
testcase_20 AC 264 ms
50,184 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