結果

問題 No.1594 Three Classes
ユーザー ComiComi
提出日時 2021-07-10 10:59:55
言語 Go
(1.22.1)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 12,666 ms
コンパイル使用メモリ 220,884 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 00:36:32
合計ジャッジ時間 12,030 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 122 ms
6,940 KB
testcase_05 AC 128 ms
6,944 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 123 ms
6,944 KB
testcase_09 AC 128 ms
6,944 KB
testcase_10 AC 128 ms
6,944 KB
testcase_11 AC 130 ms
6,940 KB
testcase_12 AC 127 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 27 ms
6,944 KB
testcase_15 AC 15 ms
6,940 KB
testcase_16 AC 8 ms
6,940 KB
testcase_17 AC 5 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func main() {
	defer writer.Flush()

	base := 3

	var n int
	fmt.Fscan(reader, &n)

	var a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}

	power := make([]int, n+1)
	power[0] = 1
	for i := 0; i < n; i++ {
		power[i+1] = power[i] * base
	}

	for i := 0; i < power[n]; i++ {

		b, c, d := 0, 0, 0
		for j := 0; j < n; j++ {
			bit := i / power[j] % base
			switch bit {
			case 0:
				b += a[j]
			case 1:
				c += a[j]
			case 2:
				d += a[j]
			}
		}

		if b == c && c == d {
			fmt.Fprintf(writer, "%v\n", "Yes")
			return
		}
	}

	fmt.Fprintf(writer, "%v\n", "No")
}
0