結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2015-12-19 09:42:29 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 827 bytes |
コンパイル時間 | 2,079 ms |
コンパイル使用メモリ | 74,252 KB |
実行使用メモリ | 43,720 KB |
最終ジャッジ日時 | 2024-09-16 08:53:43 |
合計ジャッジ時間 | 10,059 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 1 -- * 4 |
ソースコード
import java.io.*; import java.util.*; class Main4 { static int target = 0; static int[] nums; public static boolean dp (int i, int sum) { if (i >= nums.length || sum > target) return false; if (sum == target) return true; if (dp(i + 1, sum + nums[i]) || dp(i + 1, sum)) return true; return false; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); nums = new int[n]; String[] str = br.readLine().split(" "); for (int i = 0; i < n; i++) { nums[i] = Integer.parseInt(str[i]); target += nums[i]; } if (target % 2 == 1) System.out.println("impossible"); else { target /= 2; System.out.println(dp(0, 0) ? "possible" : "impossible"); } } }