結果
問題 | No.5018 Let's Make a Best-seller Book |
ユーザー |
![]() |
提出日時 | 2023-10-01 15:57:53 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 277 ms / 400 ms |
コード長 | 4,371 bytes |
コンパイル時間 | 2,752 ms |
コンパイル使用メモリ | 87,256 KB |
実行使用メモリ | 76,792 KB |
スコア | 10,882 |
平均クエリ数 | 52.00 |
最終ジャッジ日時 | 2023-10-01 15:58:26 |
合計ジャッジ時間 | 33,065 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
import java.util.Arrays;import java.util.Scanner;import java.util.SplittableRandom;import java.util.stream.IntStream;public class Main {public static void main(String[] args) throws Exception {new Main().run();}private void run() {try (final Scanner in = new Scanner(System.in)) {int T = in.nextInt();int N = in.nextInt();int Money = in.nextInt();SplittableRandom rng = new SplittableRandom(System.nanoTime());double[][] rand = new double[T][N];for (int t = 0; t < T; t++) {for (int n = 0; n < N; n++) {rand[t][n] = 1;// 0.75 + 0.5 * rng.nextDouble();}}double[] D = IntStream.range(0, N).mapToDouble(i -> 1.0).toArray();double[] minD = IntStream.range(0, N).mapToDouble(i -> 0.5).toArray();double[] maxD = IntStream.range(0, N).mapToDouble(i -> 1.5).toArray();int[] sumS = IntStream.range(0, N).map(i -> 0).toArray();int[] S = IntStream.range(0, N).map(i -> 0).toArray();int[] P = IntStream.range(0, N).map(i -> 0).toArray();int[] R = IntStream.range(0, N).map(i -> 0).toArray();for (int t = 0; t < T; t++) {if (t == 0) {// cm(2);book(N, rand, D, P, R, t, Money);} else if (t % 2 == 1) {int y = 0;for (int x = 1; x <= 5; x++) {if (500000 * (1 << (x - 1)) <= Money) {y = x;}}if (y == 0) {book(N, rand, D, P, R, t, Money);} else {cm(y);}} else {book(N, rand, D, P, R, t, Money);}Money = in.nextInt();if (Money < 0) {return;}S = IntStream.range(0, N).map(i -> in.nextInt()).toArray();for (int n = 0; n < N; n++) {sumS[n] += S[n];}for (int n = 0; n < N; n++) {if (R[n] == 0) {continue;}minD[n] = Math.max(minD[n], (S[n] + 0.000000) / (Math.pow(R[n], 0.5) * Math.pow(1.05, P[n]) * 1.25));maxD[n] = Math.min(maxD[n], (S[n] + 0.999999) / (Math.pow(R[n], 0.5) * Math.pow(1.05, P[n]) * 0.75));D[n] = (minD[n] + maxD[n]) * 0.5;}P = IntStream.range(0, N).map(i -> in.nextInt()).toArray();R = IntStream.range(0, N).map(i -> in.nextInt()).toArray();Utils.debug("Money", Money);Utils.debug("S", S);Utils.debug("P", P);Utils.debug("R", R);Utils.debug("minD", minD);Utils.debug("maxD", maxD);Utils.debug(" D", D);}} catch (Exception e) {e.printStackTrace();}}private void cm(int y) {StringBuilder sb = new StringBuilder();sb.append(2);sb.append(" ");sb.append(y);System.out.println(sb.toString());System.out.flush();}private void book(int N, double[][] rand, double[] D, int[] P, int[] R, int t, int Money) {int targetBooks = 10;int[] copies = new int[N];for (int n = 0; n < N; n++) {copies[n] = numberCopiesSoldInWeek(D[n], P[n], R[n], rand[t][n]);}StringBuilder sb = new StringBuilder();sb.append(1);for (int n = 0; n < N; n++) {sb.append(" ");if (P[n] >= 30) {targetBooks += P[n] * 3;int books = Math.max(0, targetBooks - (R[n] - copies[n]));if (Money >= 500 * books) {sb.append(books);Money -= 500 * books;} else {sb.append(0);}} else if (P[n] >= 10) {targetBooks += P[n] * 1.5;int books = Math.max(0, targetBooks - (R[n] - copies[n]));if (Money >= 500 * books) {sb.append(books);Money -= 500 * books;} else {sb.append(0);}} else if (R[n] - copies[n] < targetBooks) {int books = Math.max(0, targetBooks - (R[n] - copies[n]));if (Money >= 500 * books) {sb.append(books);Money -= 500 * books;} else {sb.append(0);}} else {sb.append(0);}// if (copies[n] > R[n]) {// sb.append(copies[n] - R[n]);// } else {// sb.append(0);// }}System.out.println(sb.toString());System.out.flush();}private int numberCopiesSoldInWeek(double D, int P, int R, double rand) {return (int) Math.min(R, Math.pow(R, 0.5) * Math.pow(1.05, P) * D * rand);}}class Utils {private Utils() {}public static final void debug(Object... o) {// System.err.println(toString(o));// System.err.flush();}public static final String toString(Object... o) {return Arrays.deepToString(o);}public static boolean isValid(int v, int min, int minUpper) {return v >= min && v < minUpper;}}