結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
holeguma
|
| 提出日時 | 2015-07-26 03:01:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 838 bytes |
| コンパイル時間 | 1,972 ms |
| コンパイル使用メモリ | 77,812 KB |
| 実行使用メモリ | 44,192 KB |
| 最終ジャッジ日時 | 2024-07-08 13:59:46 |
| 合計ジャッジ時間 | 9,421 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 2 TLE * 1 -- * 4 |
ソースコード
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);
for(int i=0;i<=w.length/2;i++){
int t=w[i];
w[i]=w[n-i-1];
w[n-i-1]=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;
}
}
holeguma