結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2017-05-04 22:10:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 145 ms / 5,000 ms |
コード長 | 914 bytes |
コンパイル時間 | 2,268 ms |
コンパイル使用メモリ | 76,432 KB |
実行使用メモリ | 41,868 KB |
最終ジャッジ日時 | 2024-06-26 10:15:43 |
合計ジャッジ時間 | 5,934 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.Arrays; import java.util.Scanner; /** * Created by whiled on 17/05/04. */ public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int[] v = new int[N]; for (int i = 0; i < N; i++) v[i] = scan.nextInt(); int sum = Arrays.stream(v).sum(); int comp = sum / 2; if (sum % 2 == 1) { System.out.println("impossible"); return; } boolean[] res = new boolean[sum + 1]; for (int i = 0; i < res.length; i++) res[i] = false; res[0] = true; for (int i = 0; i < N; i++) { for (int j = res.length - 1; j > -1; j--) { if (res[j]) res[j + v[i]] = true; } } if (res[comp]) System.out.println("possible"); else System.out.println("impossible"); } }