結果

問題 No.5018 Let's Make a Best-seller Book
ユーザー ks2mks2m
提出日時 2023-10-01 14:56:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 400 ms
コード長 6,073 bytes
コンパイル時間 5,476 ms
コンパイル使用メモリ 91,100 KB
実行使用メモリ 68,280 KB
スコア 3,856
平均クエリ数 52.00
最終ジャッジ日時 2023-10-01 14:57:10
合計ジャッジ時間 23,068 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
67,544 KB
testcase_01 AC 124 ms
65,724 KB
testcase_02 AC 141 ms
66,852 KB
testcase_03 AC 111 ms
67,220 KB
testcase_04 AC 148 ms
66,772 KB
testcase_05 AC 110 ms
67,032 KB
testcase_06 AC 122 ms
67,380 KB
testcase_07 AC 121 ms
66,724 KB
testcase_08 AC 108 ms
66,980 KB
testcase_09 AC 112 ms
66,992 KB
testcase_10 AC 113 ms
67,384 KB
testcase_11 AC 122 ms
67,332 KB
testcase_12 AC 128 ms
66,632 KB
testcase_13 AC 121 ms
67,216 KB
testcase_14 AC 123 ms
67,388 KB
testcase_15 AC 123 ms
67,188 KB
testcase_16 AC 112 ms
67,628 KB
testcase_17 AC 112 ms
67,216 KB
testcase_18 AC 121 ms
67,400 KB
testcase_19 AC 148 ms
67,108 KB
testcase_20 AC 123 ms
66,884 KB
testcase_21 AC 111 ms
67,032 KB
testcase_22 AC 112 ms
67,092 KB
testcase_23 AC 111 ms
67,508 KB
testcase_24 AC 111 ms
66,912 KB
testcase_25 AC 121 ms
67,124 KB
testcase_26 AC 159 ms
68,208 KB
testcase_27 AC 112 ms
67,036 KB
testcase_28 AC 122 ms
65,316 KB
testcase_29 AC 123 ms
67,432 KB
testcase_30 AC 122 ms
67,432 KB
testcase_31 AC 112 ms
66,800 KB
testcase_32 AC 122 ms
67,048 KB
testcase_33 AC 121 ms
66,956 KB
testcase_34 AC 134 ms
65,388 KB
testcase_35 AC 121 ms
67,172 KB
testcase_36 AC 109 ms
67,076 KB
testcase_37 AC 110 ms
66,800 KB
testcase_38 AC 113 ms
66,892 KB
testcase_39 AC 111 ms
67,388 KB
testcase_40 AC 110 ms
67,200 KB
testcase_41 AC 113 ms
67,060 KB
testcase_42 AC 122 ms
66,660 KB
testcase_43 AC 115 ms
67,668 KB
testcase_44 AC 121 ms
67,544 KB
testcase_45 AC 113 ms
66,992 KB
testcase_46 AC 114 ms
67,672 KB
testcase_47 AC 121 ms
67,484 KB
testcase_48 AC 110 ms
67,312 KB
testcase_49 AC 157 ms
67,216 KB
testcase_50 AC 111 ms
67,344 KB
testcase_51 AC 112 ms
67,448 KB
testcase_52 AC 114 ms
66,908 KB
testcase_53 AC 125 ms
66,896 KB
testcase_54 AC 122 ms
66,700 KB
testcase_55 AC 120 ms
67,040 KB
testcase_56 AC 113 ms
67,292 KB
testcase_57 AC 132 ms
67,324 KB
testcase_58 AC 123 ms
66,964 KB
testcase_59 AC 113 ms
67,300 KB
testcase_60 AC 113 ms
66,928 KB
testcase_61 AC 113 ms
67,616 KB
testcase_62 AC 113 ms
67,328 KB
testcase_63 AC 133 ms
67,184 KB
testcase_64 AC 114 ms
67,400 KB
testcase_65 AC 122 ms
67,148 KB
testcase_66 AC 123 ms
67,520 KB
testcase_67 AC 115 ms
67,308 KB
testcase_68 AC 122 ms
67,424 KB
testcase_69 AC 121 ms
67,052 KB
testcase_70 AC 121 ms
67,156 KB
testcase_71 AC 122 ms
67,144 KB
testcase_72 AC 112 ms
67,540 KB
testcase_73 AC 111 ms
67,024 KB
testcase_74 AC 110 ms
67,316 KB
testcase_75 AC 121 ms
66,960 KB
testcase_76 AC 111 ms
67,560 KB
testcase_77 AC 122 ms
67,036 KB
testcase_78 AC 121 ms
67,432 KB
testcase_79 AC 122 ms
67,208 KB
testcase_80 AC 114 ms
67,540 KB
testcase_81 AC 121 ms
64,848 KB
testcase_82 AC 132 ms
66,808 KB
testcase_83 AC 124 ms
68,280 KB
testcase_84 AC 112 ms
67,208 KB
testcase_85 AC 111 ms
65,444 KB
testcase_86 AC 113 ms
67,212 KB
testcase_87 AC 123 ms
67,228 KB
testcase_88 AC 113 ms
66,936 KB
testcase_89 AC 122 ms
67,164 KB
testcase_90 AC 120 ms
64,860 KB
testcase_91 AC 114 ms
67,588 KB
testcase_92 AC 122 ms
67,320 KB
testcase_93 AC 116 ms
67,208 KB
testcase_94 AC 112 ms
66,888 KB
testcase_95 AC 121 ms
66,688 KB
testcase_96 AC 116 ms
66,944 KB
testcase_97 AC 112 ms
67,524 KB
testcase_98 AC 112 ms
67,096 KB
testcase_99 AC 112 ms
67,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static boolean batch = false;
	static boolean readFile = false;
	static int caseNum = 1;

	static int T, N, T1;
	static int money = 2000000;
	static double[] D;
	static double[][] Z;
	static int[] mons;
	static int[][] s, p, r;

	public static void main(String[] args) throws Exception {
		if (batch) {
			readFile = true;
		}
		if (readFile) {
			if (batch) {
				long tl = 2000; // TODO
				long tw = tl - 200;
				long total = 0;
				int bidx = 0;
				int best = 0;
				int widx = 0;
				int worst = 1000000000;
				int re = 0;
				int tle = 0;
				for (int z = 0; z < 100; z++) {
					try {
						long st = System.currentTimeMillis();
						int score = solve(z);
						long time = System.currentTimeMillis() - st;
						if (time > tw) {
							System.out.println(score + "\t" + time + "ms");
							if (time > tl) {
								tle++;
							}
						} else {
							System.out.println(score);
						}
						total += score;
						if (score > best) {
							best = score;
							bidx = z;
						}
						if (score < worst) {
							worst = score;
							widx = z;
						}
					} catch (Exception e) {
						System.out.println(z + ":\t" + e.getMessage());
						re++;
					}
				}
				System.out.println("total: " + total);
				System.out.println("best: " + bidx + ": " + best);
				System.out.println("worst: " + widx + ": " + worst);
				System.out.println("RE: " + re);
				System.out.println("TLE: " + tle);
			} else {
				int score = solve(caseNum);
				System.out.println(score);
			}

		} else {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			init(br);
			solve(br);
			br.close();
		}
	}

	static int solve(int z) throws Exception {
		StringBuilder sb = new StringBuilder();
		sb.append(z);
		while (sb.length() < 4) {
			sb.insert(0, '0');
		}
		File file = new File("G:\\yuki\\007\\in\\seed_" + sb.toString() + ".txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		init(br);
		int res = solve(br);
		br.close();
		return res;
	}

	static void init(BufferedReader br) throws Exception {
		String[] sa = br.readLine().split(" ");
		T = Integer.parseInt(sa[0]);
		N = Integer.parseInt(sa[1]);
		T1 = T + 1;

		if (readFile) {
			D = new double[N];
			for (int i = 0; i < N; i++) {
				D[i] = Double.parseDouble(br.readLine());
			}

			Z = new double[T][N];
			for (int i = 0; i < T; i++) {
				sa = br.readLine().split(" ");
				for (int j = 0; j < N; j++) {
					Z[i][j] = Double.parseDouble(sa[j]);
				}
			}
		} else {
			money = Integer.parseInt(sa[2]);
		}

		mons = new int[T1];
		s = new int[T1][N];
		p = new int[T1][N];
		r = new int[T1][N];
		mons[0] = money;
	}

	static int solve(BufferedReader br) throws Exception {
		double[] d = new double[N];
		Arrays.fill(d, 1);

		for (int t = 1; t <= T; t++) {
			mons[t] = mons[t - 1];
			for (int i = 0; i < N; i++) {
				s[t][i] = s[t - 1][i];
				p[t][i] = p[t - 1][i];
				r[t][i] = r[t - 1][i];
			}
			boolean done = false;

			int pmax = 0;
			for (int i = 0; i < N; i++) {
				pmax = Math.max(pmax, p[t][i]);
			}
			if (pmax < 40) {
				int x = 0;
				int need = 500000;
				for (int i = 1; i <= 5; i++) {
					if (mons[t] >= need + 500000) {
						x = i;
					} else {
						break;
					}
					need *= 2;
				}
				if (x >= 2) {
					output2(x, t);
					done = true;
				}
			}

			if (!done) {
				int[] l = new int[N];
				double dsum = 0;
				for (int i = 0; i < N; i++) {
					dsum += d[i];
				}
				int can = mons[t] / 500;
				for (int i = 0; i < N; i++) {
					l[i] = (int) (can * d[i] / dsum);
				}
				output1(l, t);
				done = true;
			}

			boolean res = input(br, t);
			if (!res) {
				return -1;
			}
		}

		int score = score();
		return score;
	}

	static void output1(int[] l, int t) {
		int sum = 0;
		for (int i = 0; i < N; i++) {
			sum += l[i];
			r[t][i] += l[i];
		}
		if (readFile) {
			if (sum * 500 > money) {
				StringBuilder sb = new StringBuilder();
				sb.append("money:").append(money);
				sb.append(" sum:").append(sum);
				throw new RuntimeException(sb.toString());
			}

		} else {
			StringBuilder sb = new StringBuilder();
			sb.append(1);
			for (int i = 0; i < N; i++) {
				sb.append(' ').append(l[i]);
			}
			System.out.println(sb.toString());
		}
		money -= sum;
	}

	static void output2(int x, int t) {
		int val = 500000;
		for (int i = 1; i < x; i++) {
			val *= 2;
		}
		for (int i = 0; i < N; i++) {
			p[t][i] += x;
			if (p[t][i] > 60) {
				p[t][i] = 60;
			}
		}
		if (readFile) {
			if (val > money) {
				StringBuilder sb = new StringBuilder();
				sb.append("money:").append(money);
				sb.append(" val:").append(val);
				throw new RuntimeException(sb.toString());
			}

		} else {
			System.out.println("2 " + x);
		}
		money -= val;
	}

	static boolean input(BufferedReader br, int t) throws Exception {
		if (readFile) {
			for (int i = 0; i < N; i++) {
				double v1 = Math.sqrt(r[t][i]) * Math.pow(1.05, p[t][i]);
				double v2 = v1 * D[i];
				double v3 = v2 * Z[t - 1][i];
				int v4 = (int) Math.min(r[t][i], v3);
				s[t][i] = v4;
				if (r[t][i] != 0) {
					if (p[t][i] < 60 && v4 >= r[t][i] * 0.3) {
						p[t][i]++;
					}
					if (p[t][i] > -60 && v4 < r[t][i] * 0.1) {
						p[t][i]--;
					}
				}
				r[t][i] -= v4;
				money += 1000 * v4;
			}
			mons[t] = money;

		} else {
			mons[t] = Integer.parseInt(br.readLine());
			if (mons[t] == -1) {
				return false;
			}
			String[] sa = br.readLine().split(" ");
			for (int i = 0; i < N; i++) {
				s[t][i] = Integer.parseInt(sa[i]);
			}
			sa = br.readLine().split(" ");
			for (int i = 0; i < N; i++) {
				p[t][i] = Integer.parseInt(sa[i]);
			}
			sa = br.readLine().split(" ");
			for (int i = 0; i < N; i++) {
				r[t][i] = Integer.parseInt(sa[i]);
			}
		}
		return true;
	}

	static int score() {
		int ret = 0;
		for (int t = 1; t <= T; t++) {
			for (int i = 0; i < N; i++) {
				ret += s[t][i];
			}
		}
		ret = (ret + 99) / 100;
		return ret;
	}
}
0