結果

問題 No.158 奇妙なお使い
ユーザー GrenacheGrenache
提出日時 2016-06-21 23:52:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,846 ms / 5,000 ms
コード長 2,325 bytes
コンパイル時間 3,811 ms
コンパイル使用メモリ 74,096 KB
実行使用メモリ 115,912 KB
最終ジャッジ日時 2023-09-12 00:57:24
合計ジャッジ時間 35,225 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 417 ms
79,828 KB
testcase_01 AC 826 ms
90,436 KB
testcase_02 AC 281 ms
72,020 KB
testcase_03 AC 1,179 ms
94,380 KB
testcase_04 AC 1,471 ms
115,364 KB
testcase_05 AC 155 ms
56,088 KB
testcase_06 AC 1,200 ms
113,332 KB
testcase_07 AC 137 ms
56,000 KB
testcase_08 AC 367 ms
86,552 KB
testcase_09 AC 1,250 ms
98,300 KB
testcase_10 AC 1,040 ms
96,476 KB
testcase_11 AC 1,441 ms
115,912 KB
testcase_12 AC 892 ms
90,384 KB
testcase_13 AC 920 ms
90,284 KB
testcase_14 AC 1,304 ms
96,172 KB
testcase_15 AC 1,220 ms
115,364 KB
testcase_16 AC 1,460 ms
114,936 KB
testcase_17 AC 1,846 ms
115,124 KB
testcase_18 AC 696 ms
90,352 KB
testcase_19 AC 1,310 ms
94,320 KB
testcase_20 AC 986 ms
115,284 KB
testcase_21 AC 1,115 ms
115,400 KB
testcase_22 AC 1,119 ms
115,272 KB
testcase_23 AC 1,624 ms
114,980 KB
testcase_24 AC 1,834 ms
115,380 KB
testcase_25 AC 420 ms
115,536 KB
testcase_26 AC 562 ms
87,120 KB
testcase_27 AC 625 ms
92,696 KB
testcase_28 AC 1,155 ms
94,152 KB
testcase_29 AC 232 ms
89,780 KB
testcase_30 AC 713 ms
92,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder158_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a1000 = sc.nextInt();
        int a100 = sc.nextInt();
        int a1 = sc.nextInt();

        int db = sc.nextInt();
        int b1000 = sc.nextInt();
        int b100 = sc.nextInt();
        int b1 = sc.nextInt();

        int dc = sc.nextInt();
        int c1000 = sc.nextInt();
        int c100 = sc.nextInt();
        int c1 = sc.nextInt();

        int sum = a1000 * 1000 + a100 * 100 + a1;
        int[][][] dp = new int[10 + 1][100 + 1][sum + 1];

        for (int da = Math.min(db, dc); da <= sum; da++) {
        	for (int ia = 0; ia <= 10; ia++) {
        		for (int ja = 0; ja <= 100; ja++) {
        	    	if (da >= db) {
        	    		for (int i = ia; i >= 0; i--) {
        	    			if (i * 1000 > db) {
        	    				continue;
        	    			}
        	    			if (da - (ia - i) * 1000 < db) {
        	    				break;
        	    			}
        	    			for (int j = ja; j >= 0; j--) {
        	    				if (i * 1000 + j * 100 > db) {
        	    					continue;
        	    				}
        	        			if (da - (ia - i) * 1000 - (ja - j) * 100 < db) {
        	        				break;
        	        			}

        	        			dp[ia][ja][da] = Math.max(dp[ia][ja][da], dp[ia - i + b1000][ja - j + b100][da - db + b1000 * 1000 + b100 * 100 + b1] + 1);
        	    			}
        	    		}
        	    	}

        	    	if (da >= dc) {
        	    		for (int i = ia; i >= 0; i--) {
        	    			if (i * 1000 > dc) {
        	    				continue;
        	    			}
        	    			if (da - (ia - i) * 1000 < dc) {
        	    				break;
        	    			}
        	    			for (int j = ja; j >= 0; j--) {
        	    				if (i * 1000 + j * 100 > dc) {
        	    					continue;
        	    				}
        	        			if (da - (ia - i) * 1000 - (ja - j) * 100 < dc) {
        	        				break;
        	        			}

        	        			dp[ia][ja][da] = Math.max(dp[ia][ja][da], dp[ia - i + c1000][ja - j + c100][da - dc + c1000 * 1000 + c100 * 100 + c1] + 1);
        	    			}
        	    		}
        	    	}
        		}
        	}
        }

        System.out.println(dp[a1000][a100][a1000 * 1000 + a100 * 100 + a1]);

        sc.close();
    }
}
0