結果

問題 No.1594 Three Classes
ユーザー ks2mks2m
提出日時 2021-07-09 21:31:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 74,140 KB
実行使用メモリ 45,328 KB
最終ジャッジ日時 2024-04-27 23:58:39
合計ジャッジ時間 5,198 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
44,824 KB
testcase_01 AC 92 ms
39,720 KB
testcase_02 AC 109 ms
41,160 KB
testcase_03 AC 148 ms
45,076 KB
testcase_04 AC 149 ms
44,868 KB
testcase_05 AC 130 ms
45,116 KB
testcase_06 AC 124 ms
44,924 KB
testcase_07 AC 151 ms
45,112 KB
testcase_08 AC 137 ms
45,328 KB
testcase_09 AC 136 ms
44,856 KB
testcase_10 AC 124 ms
44,644 KB
testcase_11 AC 120 ms
44,632 KB
testcase_12 AC 134 ms
44,772 KB
testcase_13 AC 101 ms
39,936 KB
testcase_14 AC 149 ms
44,992 KB
testcase_15 AC 148 ms
45,324 KB
testcase_16 AC 125 ms
44,320 KB
testcase_17 AC 132 ms
44,872 KB
testcase_18 AC 103 ms
41,040 KB
testcase_19 AC 119 ms
40,900 KB
testcase_20 AC 123 ms
41,708 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