結果

問題 No.5018 Let's Make a Best-seller Book
ユーザー e869120e869120
提出日時 2023-09-24 22:30:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 400 ms
コード長 8,264 bytes
コンパイル時間 1,029 ms
コンパイル使用メモリ 89,300 KB
実行使用メモリ 24,396 KB
スコア 200,682
平均クエリ数 52.00
最終ジャッジ日時 2023-10-01 12:32:08
合計ジャッジ時間 9,410 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
23,652 KB
testcase_01 AC 34 ms
23,628 KB
testcase_02 AC 34 ms
24,024 KB
testcase_03 AC 34 ms
23,412 KB
testcase_04 AC 33 ms
23,628 KB
testcase_05 AC 33 ms
24,396 KB
testcase_06 AC 33 ms
23,628 KB
testcase_07 AC 34 ms
23,400 KB
testcase_08 AC 34 ms
24,012 KB
testcase_09 AC 33 ms
23,640 KB
testcase_10 AC 35 ms
23,652 KB
testcase_11 AC 33 ms
24,336 KB
testcase_12 AC 34 ms
23,628 KB
testcase_13 AC 33 ms
23,628 KB
testcase_14 AC 33 ms
23,412 KB
testcase_15 AC 34 ms
23,604 KB
testcase_16 AC 32 ms
24,048 KB
testcase_17 AC 33 ms
23,376 KB
testcase_18 AC 33 ms
24,396 KB
testcase_19 AC 33 ms
23,532 KB
testcase_20 AC 34 ms
24,024 KB
testcase_21 AC 35 ms
24,360 KB
testcase_22 AC 33 ms
23,388 KB
testcase_23 AC 32 ms
24,048 KB
testcase_24 AC 33 ms
23,832 KB
testcase_25 AC 35 ms
24,024 KB
testcase_26 AC 35 ms
23,412 KB
testcase_27 AC 33 ms
24,324 KB
testcase_28 AC 32 ms
23,808 KB
testcase_29 AC 33 ms
23,532 KB
testcase_30 AC 33 ms
24,024 KB
testcase_31 AC 35 ms
23,820 KB
testcase_32 AC 33 ms
23,520 KB
testcase_33 AC 33 ms
23,532 KB
testcase_34 AC 33 ms
24,252 KB
testcase_35 AC 33 ms
23,388 KB
testcase_36 AC 33 ms
24,312 KB
testcase_37 AC 33 ms
23,376 KB
testcase_38 AC 34 ms
23,664 KB
testcase_39 AC 34 ms
23,412 KB
testcase_40 AC 35 ms
24,384 KB
testcase_41 AC 35 ms
24,348 KB
testcase_42 AC 34 ms
23,664 KB
testcase_43 AC 33 ms
23,364 KB
testcase_44 AC 33 ms
23,652 KB
testcase_45 AC 32 ms
23,640 KB
testcase_46 AC 32 ms
23,652 KB
testcase_47 AC 34 ms
23,832 KB
testcase_48 AC 33 ms
23,376 KB
testcase_49 AC 33 ms
23,388 KB
testcase_50 AC 34 ms
23,388 KB
testcase_51 AC 34 ms
23,652 KB
testcase_52 AC 32 ms
23,832 KB
testcase_53 AC 33 ms
24,348 KB
testcase_54 AC 32 ms
23,652 KB
testcase_55 AC 32 ms
23,628 KB
testcase_56 AC 33 ms
24,324 KB
testcase_57 AC 34 ms
23,412 KB
testcase_58 AC 32 ms
23,592 KB
testcase_59 AC 32 ms
23,364 KB
testcase_60 AC 32 ms
24,048 KB
testcase_61 AC 32 ms
24,012 KB
testcase_62 AC 33 ms
23,844 KB
testcase_63 AC 32 ms
23,628 KB
testcase_64 AC 33 ms
23,652 KB
testcase_65 AC 32 ms
23,820 KB
testcase_66 AC 33 ms
24,324 KB
testcase_67 AC 33 ms
24,012 KB
testcase_68 AC 34 ms
24,048 KB
testcase_69 AC 33 ms
23,376 KB
testcase_70 AC 32 ms
23,640 KB
testcase_71 AC 33 ms
23,424 KB
testcase_72 AC 32 ms
23,520 KB
testcase_73 AC 32 ms
24,024 KB
testcase_74 AC 33 ms
24,360 KB
testcase_75 AC 33 ms
24,036 KB
testcase_76 AC 35 ms
24,048 KB
testcase_77 AC 33 ms
24,012 KB
testcase_78 AC 34 ms
23,844 KB
testcase_79 AC 32 ms
23,388 KB
testcase_80 AC 32 ms
24,336 KB
testcase_81 AC 32 ms
23,508 KB
testcase_82 AC 32 ms
23,820 KB
testcase_83 AC 32 ms
24,012 KB
testcase_84 AC 33 ms
23,640 KB
testcase_85 AC 32 ms
23,820 KB
testcase_86 AC 33 ms
24,012 KB
testcase_87 AC 35 ms
23,616 KB
testcase_88 AC 33 ms
24,372 KB
testcase_89 AC 33 ms
23,364 KB
testcase_90 AC 33 ms
23,844 KB
testcase_91 AC 32 ms
23,508 KB
testcase_92 AC 33 ms
24,324 KB
testcase_93 AC 32 ms
23,832 KB
testcase_94 AC 33 ms
23,628 KB
testcase_95 AC 34 ms
23,520 KB
testcase_96 AC 33 ms
23,652 KB
testcase_97 AC 35 ms
24,036 KB
testcase_98 AC 33 ms
23,412 KB
testcase_99 AC 33 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

// =============================================================== デバッグ用の出力 ===============================================================
class DebugMode {
public:
	int T = 52;
	int N = 10;
	int CurrentTurn;
	int CurrentMoney;
	int Score;
	vector<int> Sales;
	vector<int> Remain;
	vector<int> Popula;
	vector<double> D;
	vector<vector<double>> Z;

	double Randouble() {
		double s = 1, t = 0;
		for (int i = 0; i < 3; i++) {
			s /= 1024.0;
			t += 1.0 * (rand() % 1024) * s;
		}
		return t;
	}

	void Initialize() {
		CurrentMoney = 2000000;
		CurrentTurn = 0;
		Score = 0;
		Sales = vector<int>(N, 0);
		Remain = vector<int>(N, 0);
		Popula = vector<int>(N, 0);
		D = vector<double>(N, 0);
		Z = vector<vector<double>>(T, vector<double>(N, 0));
		for (int i = 0; i < N; i++) D[i] = Randouble() * 1.0 + 0.5;
		for (int i = 0; i < T; i++) {
			for (int j = 0; j < N; j++) Z[i][j] = Randouble() * 0.5 + 0.75;
		}
	}

	void Refresh() {
		int i = CurrentTurn;
		for (int j = 0; j < N; j++) Sales[j] = min(Remain[j], (int)(1.0 * pow(Remain[j], 0.5) * pow(1.05, Popula[j]) * D[j] * Z[i][j]));
		for (int j = 0; j < N; j++) {
			if (Remain[j] == 0) continue;
			if (10 * Sales[j] >= 3 * Remain[j]) Popula[j] = min(+60, Popula[j] + 1);
			if (10 * Sales[j] < 1 * Remain[j]) Popula[j] = max(-60, Popula[j] - 1);
		}
		for (int j = 0; j < N; j++) Score += Sales[j];
		for (int j = 0; j < N; j++) CurrentMoney += 1000LL * Sales[j];
		for (int j = 0; j < N; j++) Remain[j] -= Sales[j];
		CurrentTurn += 1;
	}
};

// =============================================================== デバッグ用の出力 ===============================================================
const int DEBUG = 1;
int T, N;
int Money;
int S[19], P[19], R[19];
vector<int> Ad_Record;
double Expected_D[19], Sum_D[19], Cnt_D[19];
DebugMode COMP;

void Initialize() {
	T = 0; N = 0; Money = 0; Ad_Record = vector<int>{ 0, 0 };
	for (int i = 0; i < 19; i++) {
		Expected_D[i] = 0; Sum_D[i] = 0; Cnt_D[i] = 0;
		S[i] = 0; P[i] = 0; R[i] = 0;
	}
}

void Ask(int Type, vector<int> vec) {
	if (DEBUG == 1) {
		cout << Type;
		for (int i = 0; i < vec.size(); i++) cout << " " << vec[i];
		cout << endl;
	}
	if (DEBUG == 2 && Type == 1) {
		for (int i = 0; i < N; i++) COMP.CurrentMoney -= 500 * vec[i];
		for (int i = 0; i < N; i++) COMP.Remain[i] += vec[i];
	}
	if (DEBUG == 2 && Type == 2) {
		COMP.CurrentMoney -= 500000 * (1 << (vec[0] - 1));
		for (int i = 0; i < N; i++) COMP.Popula[i] = min(60, COMP.Popula[i] + vec[0]);
	}
}

// 微調整
int Bichousei(int Goal) {
	int Max = Goal;
	for (int i = 0; i <= 4; i++) {
		int tgt1 = (1 * (Goal + i) + 9) / 10;
		int tgt2 = (3 * (Goal + i) + 9) / 10;
		int pre1 = (1 * Goal + 9) / 10;
		int pre2 = (3 * Goal + 9) / 10;
		if (tgt1 == pre1 && tgt2 == pre2) Max = Goal + i;
	}
	return Max;
}

void Decide(int turn) {
	vector<int> Sorted;
	bool AdFlag = false;
	for (int i = 1; i <= N; i++) Sorted.push_back(P[i]);
	sort(Sorted.begin(), Sorted.end());

	// 3 割目安・1 割目安を計算
	vector<int> Level3(N + 1, 0);
	vector<int> Level1(N + 1, 0);
	for (int i = 1; i <= N; i++) {
		double Lower_D = Expected_D[i] * (1.0 - 3.4 * 0.145 / sqrt(1.0 * turn));
		double Lower_T = pow(1.05, 1.0 * P[i]) * Lower_D * 0.79;
		Level3[i] = pow(Lower_T / 0.3, 2.0);
		Level1[i] = pow(Lower_T / 0.1, 2.0);
	}

	// 広告を打つ条件
	if (turn <= 15 && (Money >= 1100000 && turn - Ad_Record[Ad_Record.size() - 1] >= 2 && Sorted[7] <= 59)) AdFlag = true;
	if (turn <= 25 && (Money >= 1200000 && turn - Ad_Record[Ad_Record.size() - 1] >= 2 && Sorted[7] <= 59)) AdFlag = true;
	if (turn <= 38 && (Money >= 1300000 && turn - Ad_Record[Ad_Record.size() - 1] >= 2 && Sorted[7] <= 59)) AdFlag = true;
	if (turn <= 60 && (Money >= 1500000 && turn - Ad_Record[Ad_Record.size() - 1] >= 3 && Sorted[7] <= 59)) AdFlag = true;

	// 広告を打つ場合
	if (AdFlag == true) {
		Ask(2, vector<int>{2});
		Ad_Record.push_back(turn);
	}

	// 広告を打たない場合 (最後の方 / 売上最大化を目指す)
	else if (Sorted[9] == 60) {
		double cl = 0.0, cr = 10000.0, cm;
		vector<int> L(N, 0);
		for (int i = 0; i < 40; i++) {
			cm = (cl + cr) / 2.0;
			vector<int> vec(N, 0);
			int sum = 0;
			for (int j = 1; j <= N; j++) {
				double keisuu = pow(1.05, P[j]) * Expected_D[j];
				int meyasu = pow(keisuu / cm, 2.0);
				if (P[j] >= 60) vec[j - 1] = max(0, meyasu - R[j]);
				else if (P[j] >= 50) vec[j - 1] = max(0, min(115 * Level3[j] / 100, meyasu) - R[j]);
				else vec[j - 1] = max(0, meyasu - R[j]);
				sum += max(0, vec[j - 1]);
			}
			if (500 * sum <= Money) { cr = cm; L = vec; }
			else { cl = cm; }
		}
		Ask(1, L);
	}

	// 広告を打たない場合 (最後以外)
	else {
		vector<int> L(N, 0);
		int NeedMoney = 0;
		for (int i = 1; i <= N; i++) {
			int Goal = -1;
			if (P[i] >= 53) Goal = Level1[i];
			else if (P[i] >= 45) Goal = Level3[i] * 1.2;
			else if (P[i] >= 30) Goal = Level3[i] * 1.1;
			else if (P[i] <= 29) Goal = Level3[i];
			Goal = Bichousei(Goal);
			L[i - 1] = max(0, Goal - R[i]);
			NeedMoney += 500 * L[i - 1];
		}
		if (NeedMoney > Money) {
			for (int i = 1; i <= N; i++) L[i - 1] = (1LL * L[i - 1] * Money / NeedMoney);
		}
		Ask(1, L);
	}
}

void Refresh_D() {
	for (int i = 1; i <= N; i++) {
		if (S[i] >= 1) {
			int moto_popular = P[i];
			if (10 * S[i] >= 3 * (S[i] + R[i])) moto_popular -= 1;
			if (10 * S[i] < 1 * (S[i] + R[i])) moto_popular += 1;
			moto_popular = min(60, max(-60, moto_popular));
			double expected = (0.5 + S[i]) / (pow(1.0 * (S[i] + R[i]), 0.5) * pow(1.05, moto_popular));
			double keisuu = 1.0 - pow(1.0 / S[i], 2.0);
			Sum_D[i] += keisuu * expected;
			Cnt_D[i] += keisuu;
		}
		if (Cnt_D[i] < 0.01) Expected_D[i] = 0.6;
		else Expected_D[i] = min(1.5, max(0.5, Sum_D[i] / Cnt_D[i]));
	}
}

int main() {
	// ========================================================================= 通常モード =========================================================================
	if (DEBUG == 1) {
		Initialize();
		cin >> T >> N >> Money;
		for (int i = 1; i <= N; i++) Expected_D[i] = 1.0;

		// インタラクティブ開始
		for (int t = 1; t <= T; t++) {
			// (あ) 行動を決める
			Decide(t);

			// (い) 売上部数などを入力する
			cin >> Money;
			for (int i = 1; i <= N; i++) cin >> S[i];
			for (int i = 1; i <= N; i++) cin >> P[i];
			for (int i = 1; i <= N; i++) cin >> R[i];
			cerr << "Turn = " << t << ":" << endl;
			cerr << Money << endl;
			for (int i = 1; i <= N; i++) cerr << S[i] << " "; cerr << endl;
			for (int i = 1; i <= N; i++) cerr << P[i] << " "; cerr << endl;
			for (int i = 1; i <= N; i++) cerr << R[i] << " "; cerr << endl;
			cerr << endl;

			// D の値を更新
			Refresh_D();
		}
	}

	// ========================================================================= デバッグモード =========================================================================
	if (DEBUG == 2) {
		int NumCases = 5000;
		int ScoreSum = 0;
		int ScoreCnt = 0;
		for (int cases = 1; cases <= NumCases; cases++) {
			Initialize();
			T = 52; N = 10; Money = 2000000; COMP.Initialize();
			for (int i = 1; i <= N; i++) Expected_D[i] = 1.0;

			// インタラクティブ開始
			for (int t = 1; t <= T; t++) {
				// (あ) 行動を決める
				Decide(t);

				// (い) 売上部数などを入力する
				COMP.Refresh();
				Money = COMP.CurrentMoney;
				for (int i = 1; i <= N; i++) S[i] = COMP.Sales[i - 1];
				for (int i = 1; i <= N; i++) P[i] = COMP.Popula[i - 1];
				for (int i = 1; i <= N; i++) R[i] = COMP.Remain[i - 1];
				if (NumCases == 1) {
					cerr << "Turn = " << t << ":" << endl;
					cerr << Money << endl;
					for (int i = 1; i <= N; i++) cerr << S[i] << " "; cerr << endl;
					for (int i = 1; i <= N; i++) cerr << P[i] << " "; cerr << endl;
					for (int i = 1; i <= N; i++) cerr << R[i] << " "; cerr << endl;
					cerr << endl;
				}

				// D の値を更新
				Refresh_D();
			}
			printf("Case#% 3d: Score =% 7d\n", cases, COMP.Score);
			ScoreSum += COMP.Score;
			ScoreCnt += 1;
		}
		printf("=======================================\n");
		printf("Average Score =% 9d\n", ScoreSum / ScoreCnt);
	}
	return 0;
}
0