結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2014-11-08 14:51:59 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 797 bytes |
コンパイル時間 | 2,471 ms |
コンパイル使用メモリ | 75,108 KB |
実行使用メモリ | 108,528 KB |
最終ジャッジ日時 | 2024-12-31 08:40:00 |
合計ジャッジ時間 | 59,729 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 TLE * 9 |
ソースコード
import java.util.*; public class Main { static int sum=0; static int[] omori; static boolean dfs(int now,int sum1,int kazu){ if(now==kazu){ if(sum1==sum/2){ return true; }else{ return false; } } if(sum1>sum/2)return false; if(dfs(now+1,sum1,kazu)) return true; if(dfs(now+1,sum1+omori[now],kazu)) return true; return false; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N=sc.nextInt(); omori = new int[N]; for(int i=0;i<N;i++){ int temp=sc.nextInt(); sum+=temp; omori[i]=temp; } if(!(sum%2==0)){ System.out.println("impossible"); return; } if(dfs(0,0,N)){ System.out.println("possible"); }else{ System.out.println("impossible"); } } }