結果

問題 No.1594 Three Classes
ユーザー lavoxlavox
提出日時 2021-07-09 21:40:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 77,596 KB
実行使用メモリ 41,340 KB
最終ジャッジ日時 2024-04-28 00:05:32
合計ジャッジ時間 4,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,052 KB
testcase_01 AC 89 ms
40,028 KB
testcase_02 AC 89 ms
40,216 KB
testcase_03 AC 112 ms
41,236 KB
testcase_04 AC 132 ms
40,964 KB
testcase_05 AC 111 ms
41,076 KB
testcase_06 AC 102 ms
40,788 KB
testcase_07 AC 117 ms
41,008 KB
testcase_08 AC 114 ms
40,856 KB
testcase_09 AC 111 ms
40,792 KB
testcase_10 AC 113 ms
40,828 KB
testcase_11 AC 115 ms
41,192 KB
testcase_12 AC 103 ms
40,936 KB
testcase_13 AC 106 ms
41,204 KB
testcase_14 AC 121 ms
40,916 KB
testcase_15 AC 98 ms
40,712 KB
testcase_16 AC 120 ms
41,108 KB
testcase_17 AC 124 ms
41,340 KB
testcase_18 AC 92 ms
39,960 KB
testcase_19 AC 101 ms
40,832 KB
testcase_20 AC 101 ms
40,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static int N = 0;
	static int[] E = null;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = Integer.parseInt(sc.next());
		E = new int[N];
		for ( int i = 0 ; i < N ; i++ ) {
			E[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		if ( rec(0, 0, 0, 0) ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
	
	static boolean rec(int pos, int pa, int pb, int pc) {
		if ( pos == N ) {
			if ( pa == pb && pb == pc ) {
				return true;
			} else {
				return false;
			}
		}
		
		if ( rec(pos + 1, pa + E[pos], pb, pc) ) return true;
		if ( rec(pos + 1, pa, pb + E[pos], pc) ) return true;
		if ( rec(pos + 1, pa, pb, pc + E[pos]) ) return true;
		
		return false;
	}
}
0