結果

問題 No.1594 Three Classes
ユーザー ComiComi
提出日時 2021-07-09 22:29:59
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 868 bytes
コンパイル時間 11,472 ms
コンパイル使用メモリ 232,368 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-28 00:31:24
合計ジャッジ時間 13,552 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 57 ms
6,400 KB
testcase_04 AC 154 ms
6,400 KB
testcase_05 AC 157 ms
6,400 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 73 ms
6,400 KB
testcase_08 AC 157 ms
6,400 KB
testcase_09 AC 157 ms
6,400 KB
testcase_10 AC 157 ms
6,400 KB
testcase_11 AC 153 ms
6,400 KB
testcase_12 AC 155 ms
6,400 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 67 ms
6,400 KB
testcase_15 AC 62 ms
6,400 KB
testcase_16 AC 21 ms
6,400 KB
testcase_17 AC 76 ms
6,400 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

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

func pow(a, x int) int {
	r := 1
	for x > 0 {
		if x&1 == 1 {
			r *= a
		}
		a *= a
		x >>= 1
	}
	return r
}

func toDigits(x, base int) []int {
	if x == 0 {
		return []int{0}
	}

	ans := make([]int, 0)
	for x != 0 {
		ans = append(ans, x%base)
		x = x / base
	}
	return ans
}

func main() {
	defer writer.Flush()

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

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

	for i := 0; i < pow(3, n); i++ {
		b, c, d := 0, 0, 0
		for j, v := range toDigits(i, 3) {
			switch v {
			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