結果

問題 No.158 奇妙なお使い
ユーザー 37zigen37zigen
提出日時 2020-04-13 07:48:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 308 ms / 5,000 ms
コード長 1,788 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 77,692 KB
実行使用メモリ 120,124 KB
最終ジャッジ日時 2023-10-24 15:45:08
合計ジャッジ時間 12,367 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 256 ms
119,988 KB
testcase_01 AC 262 ms
119,768 KB
testcase_02 AC 266 ms
119,932 KB
testcase_03 AC 272 ms
120,100 KB
testcase_04 AC 304 ms
119,944 KB
testcase_05 AC 244 ms
119,920 KB
testcase_06 AC 255 ms
119,736 KB
testcase_07 AC 248 ms
119,840 KB
testcase_08 AC 274 ms
119,924 KB
testcase_09 AC 281 ms
120,124 KB
testcase_10 AC 266 ms
119,888 KB
testcase_11 AC 265 ms
119,884 KB
testcase_12 AC 253 ms
119,752 KB
testcase_13 AC 265 ms
119,788 KB
testcase_14 AC 263 ms
119,984 KB
testcase_15 AC 277 ms
119,984 KB
testcase_16 AC 274 ms
119,956 KB
testcase_17 AC 268 ms
119,784 KB
testcase_18 AC 270 ms
119,780 KB
testcase_19 AC 307 ms
119,948 KB
testcase_20 AC 272 ms
119,960 KB
testcase_21 AC 280 ms
120,044 KB
testcase_22 AC 276 ms
120,028 KB
testcase_23 AC 269 ms
119,916 KB
testcase_24 AC 280 ms
119,988 KB
testcase_25 AC 271 ms
119,940 KB
testcase_26 AC 269 ms
119,988 KB
testcase_27 AC 262 ms
119,768 KB
testcase_28 AC 262 ms
119,868 KB
testcase_29 AC 270 ms
119,872 KB
testcase_30 AC 308 ms
119,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int[] A=new int[3];
		int[] B=new int[3];
		int[] C=new int[3];
		int[] D=new int[2];
		int[][] E=new int[2][3];
		for (int i=0;i<3;++i) A[i]=sc.nextInt();
		D[0]=sc.nextInt();
		for (int i=0;i<3;++i) E[0][i]=sc.nextInt();
		D[1]=sc.nextInt();
		for (int i=0;i<3;++i) E[1][i]=sc.nextInt();
		int[][][] dp=new int[11][101][10001];
		int INF=Integer.MAX_VALUE/3;
		for (int i=0;i<dp.length;++i)
			for (int j=0;j<dp[i].length;++j)
				for (int k=0;k<dp[i][j].length;++k)
					dp[i][j][k]=-INF;
		dp[A[0]][A[1]][A[2]]=0;
		for (int sum=10000;sum>=1;--sum) {
			for (int c1000=0;1000*c1000<=sum;++c1000) {
				for (int c100=0;1000*c1000+100*c100<=sum;++c100) {
					for (int i=0;i<2;++i) {
						int c1=sum-1000*c1000-100*c100;
						if (dp[c1000][c100][c1]<0) continue;
						int res=D[i];
						int q1000=Math.min(c1000, res/1000);
						res-=q1000*1000;
						int q100=Math.min(c100, res/100);
						res-=q100*100;
						int q1=Math.min(c1, res);
						res-=q1*1;
						if (res==0) {
							int nc1000=c1000-q1000+E[i][0];
							int nc100=c100-q100+E[i][1];
							int nc1=c1-q1+E[i][2];
							dp[nc1000][nc100][nc1]=Math.max(dp[nc1000][nc100][nc1], dp[c1000][c100][c1]+1);
						}
					}
				}
			}
		}
		int ans=0;
		for (int i=0;i<dp.length;++i)
			for (int j=0;j<dp[i].length;++j)
				for (int k=0;k<dp[i][j].length;++k)
					ans=Math.max(ans, dp[i][j][k]);
		pw.println(ans);
		pw.close();
	} 
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}
0