結果

問題 No.4 おもりと天秤
ユーザー holegumaholeguma
提出日時 2015-07-26 03:24:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 617 bytes
コンパイル時間 2,709 ms
コンパイル使用メモリ 71,704 KB
実行使用メモリ 51,736 KB
最終ジャッジ日時 2023-09-08 16:23:00
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,280 KB
testcase_01 AC 43 ms
49,380 KB
testcase_02 AC 47 ms
49,832 KB
testcase_03 AC 45 ms
49,872 KB
testcase_04 AC 46 ms
50,016 KB
testcase_05 AC 59 ms
51,520 KB
testcase_06 AC 43 ms
49,124 KB
testcase_07 AC 60 ms
51,548 KB
testcase_08 AC 58 ms
51,588 KB
testcase_09 AC 59 ms
51,404 KB
testcase_10 AC 58 ms
51,492 KB
testcase_11 AC 43 ms
49,252 KB
testcase_12 AC 42 ms
49,136 KB
testcase_13 AC 43 ms
49,124 KB
testcase_14 AC 42 ms
49,332 KB
testcase_15 AC 42 ms
49,200 KB
testcase_16 AC 45 ms
49,988 KB
testcase_17 AC 43 ms
49,260 KB
testcase_18 AC 59 ms
51,624 KB
testcase_19 AC 60 ms
51,488 KB
testcase_20 AC 59 ms
51,736 KB
testcase_21 AC 59 ms
51,360 KB
testcase_22 AC 59 ms
51,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] dp=new int[10001];
dp[0]=1;
int total=0;
String[] values=br.readLine().split(" ");
for(int i=0;i<n;i++){
w[i]=Integer.parseInt(values[i]);
for(int j=10000;j>=0;j--){
if(dp[j]==1){
dp[j+w[i]]=1;
}
}
total+=w[i];
}
if(total%2==1){
System.out.println("impossible");
continue;
}
total/=2;
System.out.println(dp[total]==1?"possible":"impossible");
}
}
}
0