結果

問題 No.286 Modulo Discount Store
ユーザー buno15buno15
提出日時 2021-11-09 01:10:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 4,043 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 83,636 KB
実行使用メモリ 55,876 KB
最終ジャッジ日時 2024-04-28 13:30:26
合計ジャッジ時間 6,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
54,376 KB
testcase_01 AC 67 ms
54,576 KB
testcase_02 AC 85 ms
55,740 KB
testcase_03 AC 77 ms
54,640 KB
testcase_04 AC 77 ms
54,328 KB
testcase_05 AC 63 ms
53,988 KB
testcase_06 AC 95 ms
55,876 KB
testcase_07 AC 62 ms
54,224 KB
testcase_08 AC 79 ms
54,972 KB
testcase_09 AC 66 ms
54,500 KB
testcase_10 AC 86 ms
55,500 KB
testcase_11 AC 64 ms
54,612 KB
testcase_12 AC 65 ms
54,040 KB
testcase_13 AC 83 ms
55,744 KB
testcase_14 AC 79 ms
55,012 KB
testcase_15 AC 65 ms
54,592 KB
testcase_16 AC 77 ms
54,628 KB
testcase_17 AC 95 ms
55,816 KB
testcase_18 AC 87 ms
55,532 KB
testcase_19 AC 66 ms
54,660 KB
testcase_20 AC 82 ms
55,088 KB
testcase_21 AC 63 ms
54,640 KB
testcase_22 AC 77 ms
54,640 KB
testcase_23 AC 85 ms
55,680 KB
testcase_24 AC 66 ms
54,544 KB
testcase_25 AC 75 ms
55,408 KB
testcase_26 AC 67 ms
54,988 KB
testcase_27 AC 86 ms
55,520 KB
testcase_28 AC 98 ms
55,652 KB
testcase_29 AC 64 ms
54,068 KB
testcase_30 AC 77 ms
54,620 KB
testcase_31 AC 76 ms
54,824 KB
testcase_32 AC 79 ms
55,116 KB
testcase_33 AC 81 ms
55,284 KB
testcase_34 AC 77 ms
54,664 KB
testcase_35 AC 77 ms
54,856 KB
testcase_36 AC 63 ms
54,452 KB
testcase_37 AC 84 ms
55,228 KB
testcase_38 AC 65 ms
54,320 KB
testcase_39 AC 99 ms
55,460 KB
testcase_40 AC 75 ms
54,600 KB
testcase_41 AC 73 ms
54,620 KB
testcase_42 AC 77 ms
54,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	static final int INF = 1000000000;
	static final long MOD = 1000000007;
	static final double EPS = 1e-10;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		IO io = new IO();

		int n = io.getInt();

		int m[] = new int[n];

		for (int i = 0; i < n; i++) {
			m[i] = io.getInt();
		}

		int dp[] = new int[(1 << 20)];

		Arrays.fill(dp, INF);

		dp[0] = 0;

		for (int bit = 0; bit < (1 << n); bit++) {
			for (int i = 0; i < n; i++) {
				if ((bit & (1 << i)) != 0)
					continue;

				int sum = 0;
				for (int j = 0; j < n; j++) {
					if ((bit & (1 << j)) != 0)
						sum += m[j];
				}

				sum = sum % 1000;

				dp[bit | (1 << i)] = Math.min(dp[bit | (1 << i)], Math.max(dp[bit] + 0, dp[bit] + (m[i] - sum)));
			}
		}

		System.out.println(dp[(1 << n) - 1]);
	}
}

class Pair {
	int to;
	int cost;

	public Pair(int to, int cost) {
		this.to = to;
		this.cost = cost;
	}
}

class IO {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public IO() {

	}

	public void println(String str) {
		System.out.println(str);
	}

	public void printArr(Object o[]) {
		for (int i = 0; i < o.length; i++) {
			System.out.print(o + " ");
		}
		System.out.println();
	}

	public int getInt() throws IOException {
		return Integer.parseInt(br.readLine());
	}

	public long getLong() throws IOException {
		return Long.parseLong(br.readLine());
	}

	public double getDouble() throws IOException {
		return Double.parseDouble(br.readLine());
	}

	public String getLine() throws IOException {
		return br.readLine();
	}

	public int[] getIntArrPrim() throws IOException {
		String str[] = br.readLine().split(" ");
		int a[] = new int[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		return a;
	}

	public Integer[] getIntArr() throws IOException {
		String str[] = br.readLine().split(" ");
		Integer a[] = new Integer[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		return a;
	}

	public Long[] getLongArr() throws IOException {
		String str[] = br.readLine().split(" ");
		Long a[] = new Long[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		return a;
	}

	public long[] getLongArrPrim() throws IOException {
		String str[] = br.readLine().split(" ");
		long a[] = new long[str.length];

		for (int i = 0; i < str.length; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		return a;
	}

	public String[] getStrArr(String split) throws IOException {
		return br.readLine().split(split);
	}

	public char[] getCharArr() throws IOException {
		return br.readLine().toCharArray();
	}

	public int[][] getIntMap(int w, int h, String split) throws IOException {
		int a[][] = new int[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = Integer.parseInt(str[j]);
			}
		}

		return a;
	}

	public long[][] getLongMap(int w, int h, String split) throws IOException {
		long a[][] = new long[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = Long.parseLong(str[j]);
			}
		}

		return a;
	}

	public double[][] getDoubleMap(int w, int h, String split) throws IOException {
		double a[][] = new double[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = Double.parseDouble(str[j]);
			}
		}

		return a;
	}

	public char[][] getCharMap(int w, int h, String split) throws IOException {
		char a[][] = new char[h][w];

		for (int i = 0; i < h; i++) {
			String str[] = br.readLine().split(split);
			for (int j = 0; j < w; j++) {
				a[i][j] = str[j].charAt(0);
			}
		}

		return a;
	}
}
0