結果

問題 No.4 おもりと天秤
ユーザー holegumaholeguma
提出日時 2015-07-26 03:08:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 756 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 73,960 KB
実行使用メモリ 56,704 KB
最終ジャッジ日時 2023-09-22 23:21:36
合計ジャッジ時間 8,881 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,484 KB
testcase_01 AC 45 ms
49,324 KB
testcase_02 AC 54 ms
49,676 KB
testcase_03 AC 44 ms
49,420 KB
testcase_04 AC 42 ms
49,480 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;

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];
}
Arrays.sort(w);
if(total%2==1){
System.out.println("impossible");
continue;
}
total/=2;
System.out.println(dfs(total,n-1,w)?"possible":"impossible");
}
}
private static boolean dfs(int sum,int now,final int[] w){
if(sum<0||now<0){
return false;
}
if(sum==0){
return true;
}
return dfs(sum,now-1,w)?true:dfs(sum-w[now],now-1,w)?true:false;
}
}
0