結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2014-11-12 09:53:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 160 ms / 5,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 3,779 ms |
コンパイル使用メモリ | 78,228 KB |
実行使用メモリ | 41,752 KB |
最終ジャッジ日時 | 2024-06-26 09:03:42 |
合計ジャッジ時間 | 8,157 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main4 { public static void main(String[] args) { Main4 p = new Main4(); } public Main4() { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int[] w =new int[n]; for(int i=0;i<n;i++) w[i] = sc.nextInt(); solve(n, w); } public void solve(int n, int[] w) { Arrays.sort(w); boolean[] dp = new boolean[w[n-1]*w[n-1]+1]; dp[0] = true; for(int i=0;i<w.length;i++){ for(int j=dp.length-1;j>=0;j--){ if(j-w[i] >= 0 && dp[j-w[i]]){ dp[j] = true; } } } int sum = 0; for(int i=0;i<w.length;i++) sum += w[i]; if(sum%2==0 && dp[sum/2]) System.out.println("possible"); else System.out.println("impossible"); } }