結果
問題 | No.4 おもりと天秤 |
ユーザー | uafr_cs |
提出日時 | 2015-05-29 02:42:38 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,387 bytes |
コンパイル時間 | 2,234 ms |
コンパイル使用メモリ | 76,192 KB |
実行使用メモリ | 80,572 KB |
最終ジャッジ日時 | 2023-09-20 15:14:18 |
合計ジャッジ時間 | 12,283 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
60,308 KB |
testcase_01 | AC | 124 ms
56,184 KB |
testcase_02 | AC | 881 ms
55,728 KB |
testcase_03 | AC | 126 ms
55,524 KB |
testcase_04 | AC | 126 ms
55,840 KB |
testcase_05 | AC | 136 ms
56,280 KB |
testcase_06 | AC | 124 ms
55,764 KB |
testcase_07 | AC | 135 ms
56,040 KB |
testcase_08 | AC | 133 ms
55,692 KB |
testcase_09 | AC | 134 ms
55,692 KB |
testcase_10 | AC | 133 ms
56,068 KB |
testcase_11 | AC | 126 ms
55,596 KB |
testcase_12 | AC | 125 ms
56,052 KB |
testcase_13 | AC | 124 ms
56,032 KB |
testcase_14 | AC | 124 ms
55,704 KB |
testcase_15 | AC | 128 ms
55,880 KB |
testcase_16 | AC | 127 ms
55,936 KB |
testcase_17 | AC | 125 ms
55,760 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, int[] partial, 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; } final int rest_max = partial[N] - partial[deep]; if(current + rest_max < purpose){ 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, partial, 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]; } int[] partial = new int[N + 1]; for(int i = 1; i <= N; i++){ partial[i] += partial[i - 1] + arr[i - 1]; } final int sum = Arrays.stream(arr).sum(); final int purpose = sum / 2; System.out.println((sum % 2) == 0 && dfs(0, N, purpose, 0, arr, partial, new boolean[N]) ? "possible" : "impossible"); } }