結果
問題 | No.1594 Three Classes |
ユーザー |
![]() |
提出日時 | 2021-07-09 21:31:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 194 ms / 2,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 2,201 ms |
コンパイル使用メモリ | 75,636 KB |
実行使用メモリ | 56,872 KB |
最終ジャッジ日時 | 2024-11-16 07:29:57 |
合計ジャッジ時間 | 6,686 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
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);}}}