結果

問題 No.27 板の準備
ユーザー fujisufujisu
提出日時 2015-02-13 17:45:11
言語 Java19
(openjdk 21)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 2,933 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 74,940 KB
実行使用メモリ 51,436 KB
最終ジャッジ日時 2023-08-27 03:25:41
合計ジャッジ時間 4,571 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
49,212 KB
testcase_01 AC 50 ms
49,316 KB
testcase_02 AC 68 ms
51,356 KB
testcase_03 AC 60 ms
51,072 KB
testcase_04 AC 69 ms
51,392 KB
testcase_05 AC 69 ms
50,964 KB
testcase_06 AC 69 ms
51,436 KB
testcase_07 AC 69 ms
50,940 KB
testcase_08 AC 70 ms
51,432 KB
testcase_09 AC 63 ms
51,032 KB
testcase_10 AC 69 ms
51,024 KB
testcase_11 AC 69 ms
50,552 KB
testcase_12 AC 69 ms
51,028 KB
testcase_13 AC 69 ms
50,756 KB
testcase_14 AC 69 ms
50,956 KB
testcase_15 AC 59 ms
50,812 KB
testcase_16 AC 67 ms
50,804 KB
testcase_17 AC 60 ms
51,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	int[] dp;
	int[] l;

	int dp(int k) {
		if (k < 0) {
			return 1 << 20;
		}
		if (k == l[0] || k == l[1] || k == l[2]) {
			return 1;
		}
		if (0 <= dp[k]) {
			return dp[k];
		}

		int res = 1 << 20;
		for (int i = 0; i < 3; i++) {
			res = Math.min(res, dp(k - l[i]) + 1);
		}
		return dp[k] = res;
	}

	void run() {
		MyScanner sc = new MyScanner();

		int[] v = new int[4];
		for (int i = 0; i < 4; i++) {
			v[i] = sc.nextInt();
		}
		l = new int[3];
		dp = new int[31];

		int min = 1 << 20;
		for (int i = 1; i <= 30; i++) {
			l[0] = i;
			for (int j = i + 1; j <= 30; j++) {
				l[1] = j;
				for (int k = j + 1; k <= 30; k++) {
					l[2] = k;
					int tmp = 0;
					Arrays.fill(dp, -1);
					for (int vindex = 0; vindex < 4; vindex++) {
						tmp += dp(v[vindex]);
					}
					min = Math.min(min, tmp);
				}
			}
		}
		
		System.out.println(min);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0