結果

問題 No.158 奇妙なお使い
ユーザー 37zigen37zigen
提出日時 2020-04-13 07:40:26
言語 Java19
(openjdk 21)
結果
AC  
実行時間 307 ms / 5,000 ms
コード長 2,121 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 79,448 KB
実行使用メモリ 120,260 KB
最終ジャッジ日時 2023-10-24 15:26:24
合計ジャッジ時間 13,450 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 285 ms
120,260 KB
testcase_01 AC 268 ms
119,856 KB
testcase_02 AC 267 ms
119,892 KB
testcase_03 AC 265 ms
119,932 KB
testcase_04 AC 305 ms
119,900 KB
testcase_05 AC 248 ms
120,008 KB
testcase_06 AC 257 ms
119,900 KB
testcase_07 AC 243 ms
119,924 KB
testcase_08 AC 285 ms
119,904 KB
testcase_09 AC 261 ms
120,100 KB
testcase_10 AC 263 ms
119,832 KB
testcase_11 AC 261 ms
119,928 KB
testcase_12 AC 276 ms
117,872 KB
testcase_13 AC 282 ms
119,952 KB
testcase_14 AC 286 ms
119,912 KB
testcase_15 AC 266 ms
119,872 KB
testcase_16 AC 270 ms
119,896 KB
testcase_17 AC 275 ms
119,904 KB
testcase_18 AC 287 ms
119,900 KB
testcase_19 AC 249 ms
119,740 KB
testcase_20 AC 271 ms
119,864 KB
testcase_21 AC 269 ms
120,088 KB
testcase_22 AC 276 ms
120,080 KB
testcase_23 AC 280 ms
119,996 KB
testcase_24 AC 273 ms
119,952 KB
testcase_25 AC 276 ms
119,796 KB
testcase_26 AC 258 ms
119,952 KB
testcase_27 AC 272 ms
120,064 KB
testcase_28 AC 260 ms
119,952 KB
testcase_29 AC 254 ms
120,040 KB
testcase_30 AC 307 ms
120,124 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];
		for (int i=0;i<3;++i) A[i]=sc.nextInt();
		int Db=sc.nextInt();
		for (int i=0;i<3;++i) B[i]=sc.nextInt();
		int Dc=sc.nextInt();
		for (int i=0;i<3;++i) C[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) {
					int c1=sum-1000*c1000-100*c100;
					if (dp[c1000][c100][c1]<0) continue;
					{
						int res=Db;
						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+B[0];
							int nc100=c100-q100+B[1];
							int nc1=c1-q1+B[2];
							dp[nc1000][nc100][nc1]=Math.max(dp[nc1000][nc100][nc1], dp[c1000][c100][c1]+1);
						}
					}
					{
						int res=Dc;
						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+C[0];
							int nc100=c100-q100+C[1];
							int nc1=c1-q1+C[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