結果
問題 | No.4 おもりと天秤 |
ユーザー | doyazaki012 |
提出日時 | 2015-05-27 23:47:11 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,135 bytes |
コンパイル時間 | 2,355 ms |
コンパイル使用メモリ | 74,376 KB |
実行使用メモリ | 57,744 KB |
最終ジャッジ日時 | 2023-09-20 16:57:53 |
合計ジャッジ時間 | 6,948 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,676 KB |
testcase_01 | AC | 126 ms
55,896 KB |
testcase_02 | AC | 151 ms
56,612 KB |
testcase_03 | AC | 145 ms
57,540 KB |
testcase_04 | AC | 145 ms
57,272 KB |
testcase_05 | RE | - |
testcase_06 | AC | 129 ms
55,708 KB |
testcase_07 | RE | - |
testcase_08 | AC | 136 ms
55,760 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 149 ms
57,392 KB |
testcase_12 | AC | 125 ms
55,868 KB |
testcase_13 | AC | 125 ms
55,724 KB |
testcase_14 | AC | 125 ms
55,644 KB |
testcase_15 | AC | 122 ms
55,576 KB |
testcase_16 | AC | 151 ms
57,744 KB |
testcase_17 | AC | 128 ms
55,816 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
ソースコード
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"); } } }