結果

問題 No.4 おもりと天秤
ユーザー kuramukuramu
提出日時 2016-01-20 15:46:43
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,120 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 54,532 KB
最終ジャッジ日時 2023-10-21 13:32:12
合計ジャッジ時間 4,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,704 KB
testcase_01 AC 47 ms
53,544 KB
testcase_02 AC 49 ms
53,716 KB
testcase_03 AC 50 ms
53,704 KB
testcase_04 AC 47 ms
53,704 KB
testcase_05 AC 59 ms
54,532 KB
testcase_06 RE -
testcase_07 AC 58 ms
54,264 KB
testcase_08 AC 48 ms
53,568 KB
testcase_09 AC 58 ms
54,280 KB
testcase_10 AC 60 ms
54,312 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 AC 50 ms
53,708 KB
testcase_14 WA -
testcase_15 AC 50 ms
53,724 KB
testcase_16 AC 49 ms
53,724 KB
testcase_17 AC 47 ms
53,708 KB
testcase_18 AC 55 ms
53,704 KB
testcase_19 AC 61 ms
54,272 KB
testcase_20 AC 64 ms
54,268 KB
testcase_21 AC 55 ms
53,704 KB
testcase_22 AC 58 ms
54,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
		      int N = Integer.parseInt(stdReader.readLine());
		      String[] temps = stdReader.readLine().split(" ");
		      int[] nums = new int[N+1];
		      int sum = 0;
		      for(int i=0;i<N;i++){
		    	  nums[i+1] = Integer.parseInt(temps[i]);
		    	  sum += nums[i+1];
		      }
		      if(sum%2 != 0){
		    	  System.out.println("impossible");
		    	  return;
		      }
		      Arrays.sort(nums);
		      int half = sum/2;
		      boolean[] dp = new boolean[half+1];
		      for(int i=1;i<nums.length;i++){
		    	  dp[nums[i]] = true;
		    	  for(int j=1;j<half+1;j++){
		    		  if(dp[j] && j+ nums[i] <= half) dp[j+nums[i]] = true;
		    	  }
		      }
		      if(dp[half]) System.out.println("possible");
		      else System.out.println("impossible");
	    	  } catch (IOException e) {
			e.printStackTrace();
	      }
	}	
}
0