結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2015-04-16 18:24:48 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,353 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 79,376 KB |
実行使用メモリ | 177,508 KB |
最終ジャッジ日時 | 2024-07-04 14:57:34 |
合計ジャッジ時間 | 8,113 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 13 |
ソースコード
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; for(int i=0; i<n; i++){ for(int j=0; j<=i; j++){ if(judge[i][j][h]){ pos = true; System.out.println(i+" "+j+" "+h); System.out.println("possible"); break; } } } if(!pos){ System.out.println("impossible"); } } } }