結果

問題 No.1594 Three Classes
ユーザー lavoxlavox
提出日時 2021-07-09 21:40:18
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 2,201 ms
使用メモリ 38,612 KB
最終ジャッジ日時 2022-12-17 01:44:01
合計ジャッジ時間 5,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 112 ms
38,456 KB
testcase_01 AC 92 ms
37,372 KB
testcase_02 AC 94 ms
37,248 KB
testcase_03 AC 95 ms
37,244 KB
testcase_04 AC 108 ms
38,216 KB
testcase_05 AC 103 ms
38,280 KB
testcase_06 AC 93 ms
37,408 KB
testcase_07 AC 95 ms
37,424 KB
testcase_08 AC 110 ms
38,240 KB
testcase_09 AC 108 ms
38,612 KB
testcase_10 AC 105 ms
38,180 KB
testcase_11 AC 105 ms
38,352 KB
testcase_12 AC 106 ms
38,156 KB
testcase_13 AC 95 ms
37,424 KB
testcase_14 AC 101 ms
38,344 KB
testcase_15 AC 102 ms
38,124 KB
testcase_16 AC 98 ms
37,356 KB
testcase_17 AC 98 ms
37,448 KB
testcase_18 AC 94 ms
37,164 KB
testcase_19 AC 92 ms
37,224 KB
testcase_20 AC 95 ms
37,364 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