結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2015-04-16 18:27:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 417 ms / 5,000 ms |
コード長 | 1,302 bytes |
コンパイル時間 | 2,137 ms |
コンパイル使用メモリ | 77,712 KB |
実行使用メモリ | 176,784 KB |
最終ジャッジ日時 | 2024-06-26 09:10:47 |
合計ジャッジ時間 | 8,216 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner koko = new Scanner(System.in); int n = koko.nextInt(); int total = 0; int[] w = new int[n]; for(int i=0; i<n; i++){ w[i]=koko.nextInt(); total=total+w[i]; } if(total%2!=0){ System.out.println("impossible"); }else{ int h = total/2; boolean[][][] judge = new boolean[n][n][total]; judge[0][0][0]=true; for(int i=0; i<n-1; i++){ for(int j=0; j<n-1; j++){ for(int k=0; k<h; k++){ if(judge[i][j][k]){ judge[i+1][j][k]=true; judge[i+1][j+1][k+w[i]]=true; } } } } boolean pos = false; loop1: for(int i=0; i<n; i++){ for(int j=0; j<=i; j++){ if(judge[i][j][h]){ pos = true; System.out.println("possible"); break loop1; } } } if(!pos){ System.out.println("impossible"); } } } }