結果

問題 No.5018 Let's Make a Best-seller Book
ユーザー EvbCFfp1XB
提出日時 2023-10-01 14:37:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 267 ms / 400 ms
コード長 2,974 bytes
コンパイル時間 5,309 ms
コンパイル使用メモリ 83,784 KB
実行使用メモリ 75,560 KB
スコア 100
平均クエリ数 52.00
最終ジャッジ日時 2023-10-01 14:38:18
合計ジャッジ時間 35,628 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] 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) {
					StringBuilder sb = new StringBuilder();
					sb.append(1);
					for (int n = 0; n < N; n++) {
						sb.append(" ");
						sb.append(10);
					}
					System.out.println(sb.toString());
					System.out.flush();
				} else if (t % 2 == 1) {
					int y = 0;
					for (int x = 1; x <= 5; x++) {
						if (500000 << x <= Money) {
							y = x;
						}
					}
					if (y == 0) {
						book(N, rand, D, P, R, t);
					} else {
						cm(y);
					}
				} else {
					book(N, rand, D, P, R, t);
				}

				Money = in.nextInt();
				if (Money < 0) {
					return;
				}
				S = IntStream.range(0, N).map(i -> in.nextInt()).toArray();
				for (int n = 0; n < N; n++) {
					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();

			}
		} 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[] 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 (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);
	}

}
0