結果

問題 No.4 おもりと天秤
ユーザー doyazaki012doyazaki012
提出日時 2015-05-27 23:52:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 1,137 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 73,992 KB
実行使用メモリ 115,708 KB
最終ジャッジ日時 2023-09-08 16:17:39
合計ジャッジ時間 7,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
113,856 KB
testcase_01 AC 158 ms
113,800 KB
testcase_02 AC 178 ms
115,464 KB
testcase_03 AC 175 ms
115,612 KB
testcase_04 AC 176 ms
115,616 KB
testcase_05 AC 177 ms
113,788 KB
testcase_06 AC 162 ms
113,788 KB
testcase_07 AC 183 ms
114,044 KB
testcase_08 AC 169 ms
113,696 KB
testcase_09 AC 183 ms
115,708 KB
testcase_10 AC 178 ms
113,716 KB
testcase_11 AC 167 ms
115,516 KB
testcase_12 AC 154 ms
113,744 KB
testcase_13 AC 155 ms
113,764 KB
testcase_14 AC 156 ms
113,520 KB
testcase_15 AC 156 ms
113,816 KB
testcase_16 AC 180 ms
115,520 KB
testcase_17 AC 159 ms
114,092 KB
testcase_18 AC 183 ms
115,048 KB
testcase_19 AC 178 ms
114,204 KB
testcase_20 AC 182 ms
114,108 KB
testcase_21 AC 178 ms
114,312 KB
testcase_22 AC 180 ms
114,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

//memo


class Yuki4_2{
	public static final int MAX_N = 100;
	public static final int MAX_W = 110000;

	public static boolean[][] dpChecker = new boolean[MAX_N+1][MAX_W+1];
	public static int[][] dpMemo = new int[MAX_N+1][MAX_W+1];
	public static int[] w = new int[MAX_N+1];

	static int myDP(int i,int j){
		//System.out.println(i+" "+j);
		if(dpChecker[i][j] == true) {return dpMemo[i][j];}
		int res;
		if(i==MAX_N){res = 0;}
		else if(j < w[i]){res = myDP(i+1,j);}
		else{
			if(myDP(i+1,j-w[i])+w[i] < myDP(i+1,j)){
				res = myDP(i+1,j);
			}else{
				res = myDP(i+1,j-w[i])+w[i];
			}
		}

		dpChecker[i][j] = true;
		dpMemo[i][j] = res;
		return res;
	}


	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int sumW = 0;
		for(int i=0;i<n;i++){
			w[i] = stdIn.nextInt();
			sumW += w[i];
		}
		if(sumW%2 == 0){
			int answer = myDP(0,sumW/2);
			if(answer == sumW/2){
				System.out.println("possible");
			}else{
				//System.out.println(answer);
				System.out.println("impossible");
			}
		}else{
			System.out.println("impossible");
		}
	}
}
0