結果

問題 No.1594 Three Classes
ユーザー ks2mks2m
提出日時 2021-07-09 21:31:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 71,568 KB
実行使用メモリ 59,052 KB
最終ジャッジ日時 2023-08-10 06:40:06
合計ジャッジ時間 5,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
58,836 KB
testcase_01 AC 115 ms
55,748 KB
testcase_02 AC 111 ms
55,900 KB
testcase_03 AC 156 ms
59,052 KB
testcase_04 AC 155 ms
58,244 KB
testcase_05 AC 146 ms
58,876 KB
testcase_06 AC 142 ms
58,260 KB
testcase_07 AC 156 ms
58,648 KB
testcase_08 AC 154 ms
58,072 KB
testcase_09 AC 163 ms
58,060 KB
testcase_10 AC 137 ms
58,604 KB
testcase_11 AC 136 ms
58,768 KB
testcase_12 AC 143 ms
58,608 KB
testcase_13 AC 119 ms
56,032 KB
testcase_14 AC 158 ms
58,464 KB
testcase_15 AC 157 ms
58,796 KB
testcase_16 AC 155 ms
58,416 KB
testcase_17 AC 162 ms
58,896 KB
testcase_18 AC 120 ms
56,260 KB
testcase_19 AC 128 ms
55,916 KB
testcase_20 AC 123 ms
56,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static String ans = "No";

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] e = new int[n];
		for (int i = 0; i < n; i++) {
			e[i] = sc.nextInt();
		}
		sc.close();

		dfs(e, 0, new int[n]);
		System.out.println(ans);
	}

	static void dfs(int[] e, int x, int[] g) {
		if (x == e.length) {
			int[] p = new int[3];
			for (int i = 0; i < e.length; i++) {
				p[g[i]] += e[i];
			}
			if (p[0] == p[1] && p[1] == p[2]) {
				ans = "Yes";
			}
			return;
		}

		for (int i = 0; i < 3; i++) {
			g[x] = i;
			dfs(e, x + 1, g);
		}
	}
}
0