結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2015-04-21 22:04:44 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 152 ms / 5,000 ms |
コード長 | 755 bytes |
コンパイル時間 | 2,609 ms |
コンパイル使用メモリ | 79,380 KB |
実行使用メモリ | 41,712 KB |
最終ジャッジ日時 | 2024-06-26 09:11:09 |
合計ジャッジ時間 | 6,742 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.*; import java.util.stream.*; public class Main { private void solve() { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); int[] ws = Stream.of(sc.nextLine().split(" ")) .mapToInt(Integer::parseInt) .toArray(); int sum = Arrays.stream(ws).sum(); boolean[] ok = new boolean[sum+1]; ok[0] = true; for(int w : ws) { for(int i=sum; i>=0; i--) { if(ok[i]) { ok[i+w] = true; } } } System.out.println(ok[sum/2] && sum%2==0 ? "possible" : "impossible"); } public static void main(String[] args) { new Main().solve(); } }