結果

問題 No.4 おもりと天秤
ユーザー kuramukuramu
提出日時 2016-01-20 16:09:54
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,144 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 77,932 KB
実行使用メモリ 54,252 KB
最終ジャッジ日時 2023-10-21 13:32:34
合計ジャッジ時間 4,575 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,576 KB
testcase_01 AC 56 ms
53,436 KB
testcase_02 AC 57 ms
52,436 KB
testcase_03 AC 57 ms
53,580 KB
testcase_04 AC 57 ms
53,580 KB
testcase_05 AC 67 ms
53,084 KB
testcase_06 RE -
testcase_07 AC 66 ms
53,080 KB
testcase_08 AC 56 ms
53,388 KB
testcase_09 AC 68 ms
54,152 KB
testcase_10 AC 66 ms
54,148 KB
testcase_11 AC 56 ms
53,576 KB
testcase_12 RE -
testcase_13 AC 56 ms
53,576 KB
testcase_14 AC 55 ms
53,576 KB
testcase_15 AC 56 ms
53,588 KB
testcase_16 AC 56 ms
53,576 KB
testcase_17 AC 56 ms
53,584 KB
testcase_18 AC 66 ms
53,080 KB
testcase_19 AC 66 ms
54,140 KB
testcase_20 AC 65 ms
54,136 KB
testcase_21 AC 66 ms
54,252 KB
testcase_22 AC 67 ms
54,152 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];
		      dp[nums[N]] =  true;
		      for(int i=N-1;0<i;i--){
		    	  for(int j =half;0<j;j--){
		    		  if(dp[j] && j + nums[i] <= half) dp[j+nums[i]] = true;  
		    	  }
		    	  dp[nums[i]] = true;
		      }
		      if(dp[half]) System.out.println("possible");
		      else System.out.println("impossible");
	    	  } catch (IOException e) {
			e.printStackTrace();
	      }
	}	
}
0