結果
問題 | No.4 おもりと天秤 |
ユーザー | uafr_cs |
提出日時 | 2015-05-29 02:36:36 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,087 bytes |
コンパイル時間 | 2,227 ms |
コンパイル使用メモリ | 80,624 KB |
実行使用メモリ | 60,552 KB |
最終ジャッジ日時 | 2023-09-20 15:09:26 |
合計ジャッジ時間 | 12,401 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
55,744 KB |
testcase_01 | WA | - |
testcase_02 | AC | 851 ms
53,668 KB |
testcase_03 | AC | 129 ms
56,052 KB |
testcase_04 | AC | 131 ms
56,052 KB |
testcase_05 | AC | 138 ms
55,956 KB |
testcase_06 | AC | 129 ms
55,476 KB |
testcase_07 | AC | 137 ms
55,676 KB |
testcase_08 | WA | - |
testcase_09 | AC | 141 ms
55,932 KB |
testcase_10 | AC | 144 ms
55,444 KB |
testcase_11 | AC | 131 ms
55,504 KB |
testcase_12 | AC | 130 ms
53,812 KB |
testcase_13 | AC | 132 ms
56,040 KB |
testcase_14 | AC | 138 ms
55,640 KB |
testcase_15 | AC | 129 ms
55,728 KB |
testcase_16 | AC | 129 ms
55,764 KB |
testcase_17 | AC | 128 ms
55,824 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static boolean dfs(int deep, int N, int purpose, int current, int[] array, boolean[] used){ //System.out.println(deep + " " + purpose + " " + current); if(purpose == current){ return true; }else if(purpose < current){ return false; }else if(deep >= N){ return false; } for(int i = deep; i < N; i++){ if(!used[i]){ used[i] = true; if(dfs(deep + 1, N, purpose, current + array[i], array, used)){ return true; } used[i] = false; } } return false; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = -sc.nextInt(); } Arrays.sort(arr); for(int i = 0; i < N; i++){ arr[i] = -arr[i]; } final int purpose = Arrays.stream(arr).sum() / 2; System.out.println(dfs(0, N, purpose, 0, arr, new boolean[N]) ? "possible" : "impossible"); } }