結果

問題 No.4 おもりと天秤
ユーザー doyazaki012doyazaki012
提出日時 2015-05-27 23:43:23
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,133 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 75,492 KB
実行使用メモリ 81,448 KB
最終ジャッジ日時 2023-09-20 16:56:21
合計ジャッジ時間 9,517 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 121 ms
55,596 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 132 ms
55,924 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

//memo


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

	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