結果
問題 | No.4 おもりと天秤 |
ユーザー | holeguma |
提出日時 | 2015-07-26 02:43:40 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 721 bytes |
コンパイル時間 | 2,015 ms |
コンパイル使用メモリ | 74,192 KB |
実行使用メモリ | 56,208 KB |
最終ジャッジ日時 | 2023-09-22 23:18:48 |
合計ジャッジ時間 | 9,755 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,416 KB |
testcase_01 | AC | 44 ms
49,592 KB |
testcase_02 | AC | 47 ms
49,292 KB |
testcase_03 | AC | 44 ms
49,600 KB |
testcase_04 | AC | 44 ms
49,272 KB |
testcase_05 | AC | 44 ms
49,368 KB |
testcase_06 | AC | 43 ms
49,108 KB |
testcase_07 | AC | 44 ms
49,376 KB |
testcase_08 | AC | 43 ms
49,248 KB |
testcase_09 | AC | 44 ms
49,164 KB |
testcase_10 | AC | 43 ms
49,144 KB |
testcase_11 | AC | 43 ms
49,516 KB |
testcase_12 | AC | 43 ms
49,228 KB |
testcase_13 | AC | 42 ms
49,432 KB |
testcase_14 | AC | 43 ms
49,164 KB |
testcase_15 | AC | 42 ms
48,992 KB |
testcase_16 | AC | 43 ms
49,188 KB |
testcase_17 | AC | 43 ms
49,072 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
import java.io.*; class Main{ public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=""; while((line=br.readLine())!=null){ int n=Integer.parseInt(line); int[] w=new int[n]; int total=0; String[] values=br.readLine().split(" "); for(int i=0;i<n;i++){ w[i]=Integer.parseInt(values[i]); total+=w[i]; } if(total%2==1){ System.out.println("impossible"); continue; } total/=2; System.out.println(dfs(total,0,w)?"possible":"impossible"); } } private static boolean dfs(int sum,int now,final int[] w){ if(sum==0){ return true; } if(now>=w.length||sum<0){ return false; } return dfs(sum-w[now],now+1,w)?true:dfs(sum,now+1,w)?true:false; } }