結果
問題 | No.5018 Let's Make a Best-seller Book |
ユーザー |
![]() |
提出日時 | 2023-10-02 11:06:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 167 ms / 400 ms |
コード長 | 10,589 bytes |
コンパイル時間 | 2,159 ms |
コンパイル使用メモリ | 87,052 KB |
実行使用メモリ | 93,204 KB |
スコア | 173,682 |
平均クエリ数 | 52.00 |
最終ジャッジ日時 | 2023-10-02 11:06:56 |
合計ジャッジ時間 | 22,542 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
from random import gauss, random, randrangetry:LOCALexcept NameError:LOCAL = 0if LOCAL:import optunaDEBUG = 1print("LOOP ?")LOOP = int(input())else:DEBUG = 0LOOP = 1def receive():global Pglobal Rglobal moneyglobal MI, MAglobal sell_countif DEBUG:sell_count = [min(R[i], int(R[i] ** 0.5 * 1.05 ** P[i] * D[i] * (0.75 + random() * 0.5))) for i in range(N)]money += 1000 * sum(sell_count)else:money = int(input())sell_count = [int(a) for a in input().split()]for i in range(N):if R[i]:ma = (sell_count[i] + 1) / (R[i] ** 0.5 * 0.75 * 1.05 ** P[i])mi = sell_count[i] / (R[i] ** 0.5 * 1.25 * 1.05 ** P[i])MI[i] = max(mi, MI[i])if sell_count[i] < R[i]:MA[i] = min(ma, MA[i])for i in range(N):if R[i]:if sell_count[i] * 10 >= 3 * R[i]:P[i] = min(P[i] + 1, 60)elif sell_count[i] * 10 < R[i]:P[i] = max(P[i] - 1, -60)if DEBUG:for i in range(N):R[i] -= sell_count[i]else:for i, a in enumerate(input().split()):P[i] = int(a)for i, a in enumerate(input().split()):R[i] = int(a)for i in range(N):total_sell_count[i] += sell_count[i]def adj(n):if n < 4:return 3if n % 10 < 3:return n // 10 * 10if n % 10 < 6:return n // 10 * 10 + 3return n // 10 * 10 + 6def Order(f1, f2, f3, f4, f5, f6, f7, g1, g2):global Pglobal Rglobal moneyglobal best_allocation_flgtarget = 10buy_count = [0] * Nbest_allocation = [((MA[i] + MI[i]) / 2 * 1.05 ** P[i]) ** 2 for i in range(N)]su = sum(best_allocation)for i in range(N):best_allocation[i] *= 10 ** 8best_allocation[i] = adj(int(best_allocation[i]))best_allocation_flg = [0] * Nfor i in range(N):a30 = (10 / 3 * 1.05 ** P[i] * (MA[i] * 0.0 + MI[i] * 1.0)) ** 2b30 = (10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2if t == 0:target = 3elif t < 5:target = adj(int(a30 * f1))elif t < 12:target = adj(int(b30 * f2))elif t < 20:target = adj(int(b30 * f3))elif t < (20 * 0.75 + g2 * 0.25) and P[i] < g1:target = adj(int(b30 * f4))elif t < (20 * 0.5 + g2 * 0.5) and P[i] < g1:target = adj(int(b30 * f5))elif t < (20 * 0.25 + g2 * 0.75) and P[i] < g1:target = adj(int(b30 * f6))elif t < g2 and P[i] < g1:target = adj(int(b30 * f7))elif t < 100:target = best_allocation[i]best_allocation_flg[i] = 1else:assert 0buy_count[i] = max(0, target - R[i])if 1:su_best = sum([a for a, f in zip(best_allocation, best_allocation_flg) if f])su_R = sum([r for r, f in zip(R, best_allocation_flg) if f])used = sum([max(t - r, 0) for t, r, f in zip(buy_count, R, best_allocation_flg) if not f])avail = max(0, money // 500 - used + su_R)for i in range(N):if best_allocation_flg[i]:buy_count[i] = adj(int(best_allocation[i] / su_best * avail - R[i]))# buy_count[i] = adj(int(best_allocation[i] / su_best * avail))while 1:r = sum(buy_count) * 500 / moneyif r <= 1:breakfor i in range(N):buy_count[i] = adj(int(buy_count[i] / r))money -= sum(buy_count) * 500if money < 0:while 1:passassert money >= 0for i in range(N):R[i] += buy_count[i]if not DEBUG:print(1, *buy_count)def Advertise(x):global moneymoney -= 500000 << x - 1if money < 0:while 1:passassert money >= 0for i in range(N):P[i] = min(P[i] + x, 60)if not DEBUG:print(2, x)def main_loop(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1, g2):global T, N, moneyglobal MI, MA, P, R, t, D, total_sell_count, LOOPglobal total_totalret = 0main_loop_loop = 2000for _ in range(main_loop_loop):ret += main(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1, g2)return ret / main_loop_loopdef main(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1, g2):global T, N, moneyglobal MI, MA, P, R, t, D, total_sell_count, LOOPglobal total_totalif DEBUG:T, N, money = 52, 10, 2 * 10 ** 6D = [random() + 0.5 for _ in range(N)]# D = [random() / 2 + 1.0 for _ in range(N)]else:T, N, money = map(int, input().split())D = [random() + 0.5 for _ in range(N)]total_sell_count = [0] * Nsell_count = [0] * Nbest_allocation_flg = [0] * NMA = [1.5] * NMI = [0.5] * NP = [0] * NR = [0] * Nfor t in range(T):if (adv_l3 < t < adv_r3 and money >= adv_m3) and sorted(P)[-1] < 58:Advertise(3)elif (adv_l2 < t < adv_r2 and money >= adv_m2) and sorted(P)[-1] < 59:Advertise(2)elif (0 < t < 0 and money >= 1200000) and sorted(P)[-1] < 59:Advertise(2)elif t < 4 and money >= 6000000:Advertise(4)elif t < 4 and money >= 3000000:Advertise(3)else:Order(f1, f2, f3, f4, f5, f6, f7, g1, g2)if DEBUG:if LOOP == 1:print("-" * 20)print("t =", t)print("Money =", money)receive()if DEBUG:if LOOP == 1:print("Money =", money)print("P =", P)print("R =", R)print("sell_count =", sell_count)print("MI =", ["{:.2f}".format(a) for a in MI])print("MA =", ["{:.2f}".format(a) for a in MA])print("D =", ["{:.2f}".format(a) for a in D])print("Flg =", best_allocation_flg)print("Total =", sum(total_sell_count), total_sell_count)if LOCAL:total_total += sum(total_sell_count)if LOCAL and 4 >= LOOP > 1:print("loop =", loop, total_sell_count, sum(total_sell_count), round(total_total / (loop + 1)))return sum(total_sell_count)def objective(trial):adv_l2 = trial.suggest_int('adv_l2', 1, 5)adv_r2 = trial.suggest_int('adv_r2', 25, 45)adv_m2 = trial.suggest_float('adv_m2', 105 * 10 ** 4, 130 * 10 ** 4)adv_l3 = trial.suggest_int('adv_l3', 15, 20)adv_r3 = trial.suggest_int('adv_r3', 30, 50)adv_m3 = trial.suggest_float('adv_m3', 220 * 10 ** 4, 300 * 10 ** 4)f1 = trial.suggest_float('f1', 0.70, 0.90)f2 = trial.suggest_float('f2', 0.40, 0.70)f3 = trial.suggest_float('f3', 0.30, 0.60)f4 = trial.suggest_float('f4', 0.20, 0.60)f5 = trial.suggest_float('f5', 0.20, 0.55)f6 = trial.suggest_float('f6', 0.10, 0.50)f7 = trial.suggest_float('f7', 0.10, 0.50)g1 = trial.suggest_int('g1', 40, 60)g2 = trial.suggest_int('g2', 40, 50)score = main_loop(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1, g2)return -scoreOP = 0if OP:T, N, money = None, None, NoneMI, MA, D = None, None, NoneP, R, t, total_sell_count = None, None, None, Nonestudy = optuna.create_study()study.optimize(objective, n_trials=1000)print("Best Params =", study.best_params)print("Best Score =", study.best_value)else:total_total = 0_t = 0Params = {'adv_l2': 1, 'adv_r2': 33, 'adv_m2': 1150894.1177157715, 'adv_l3': 16, 'adv_r3': 50, 'adv_m3': 2946328.352258085, 'f1': 0.7577663544011545, 'f2': 0.4828227141584538, 'f3': 0.4972439506386438, 'f4': 0.5629233324271415, 'f5': 0.5131416541498899, 'f6': 0.45233343537815346, 'f7': 0.438522644272038, 'g1': 45, 'g2': 44}for k, v in Params.items():exec(k + str(" = ") + str(v))for loop in range(LOOP):_t += main(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1, g2)if LOCAL:print("LOOP =", LOOP, round(total_total / LOOP), round(_t / LOOP))_ = '''Best Params = {'adv_l2': 1, 'adv_r2': 33, 'adv_m2': 1150894.1177157715, 'adv_l3': 16, 'adv_r3': 50, 'adv_m3': 2946328.352258085, 'f1': 0.7577663544011545, 'f2': 0.4828227141584538, 'f3': 0.4972439506386438, 'f4': 0.5629233324271415, 'f5': 0.5131416541498899, 'f6': 0.45233343537815346, 'f7': 0.438522644272038, 'g1': 45, 'g2': 44}Best Score = -182240.325Best Params = {'adv_l2': 1, 'adv_r2': 33, 'adv_m2': 1059258.2189775354,'adv_l3': 18, 'adv_r3': 48, 'adv_m3': 2686445.781066581,'f1': 0.7977800220202227, 'f2': 0.551032831198818, 'f3': 0.5299220276322835,'f4': 0.5498393778548679, 'f5': 0.42812314931333745, 'f6': 0.18079451958248885,'f7': 0.1333551668112509, 'g1': 41, 'g2': 47}Best Score = -179423.575Best Params = {'adv_l2': 3, 'adv_r2': 34, 'adv_m2': 1077583.6894016732,'adv_l3': 15, 'adv_r3': 39, 'adv_m3': 2641221.6852187263,'f1': 0.6608625427038423, 'f2': 0.536255559402984, 'f3': 0.544224068328003,'f4': 0.5930760450080326, 'f5': 0.5296353385134165, 'f6': 0.4997011249487702,'f7': 0.18112500260814665, 'g1': 51, 'g2': 50}Best Score = -179557.162·Best Params = {'adv_l2': 4, 'adv_r2': 34, 'adv_m2': 1186197.4406347682,'adv_l3': 18, 'adv_r3': 43, 'adv_m3': 2931408.6158438902,'f1': 0.8329027232431818, 'f2': 0.4383836146967173, 'f3': 0.5335765817506617,'f4': 0.5582777882317832, 'f5': 0.48926189592932584, 'f6': 0.3277355570137359,'f7': 0.19762882186386968, 'g1': 48, 'g2': 44}Best Params = {'adv_l2': 1, 'adv_r2': 34, 'adv_m2': 1071996.048402824,'adv_l3': 18, 'adv_r3': 39, 'adv_m3': 2506057.429736735,'f1': 0.7530461775247944, 'f2': 0.5784067161547253, 'f3': 0.3998962794048304,'f4': 0.5294730042963244, 'f5': 0.4904776465015429, 'f6': 0.3933636958636354,'f7': 0.2161664699683005, 'g1': 50}Best Score = -174102.633Best Params = {'adv_l3': 12.316204575888603, 'adv_r3': 47.71022165578954,'adv_m': 2942277.919106235, 'f1': 0.7837350220521555, 'f2': 0.5465937999426904,'f3': 0.46522777277350125, 'f4': 0.4715163081906667, 'f5': 0.5818274160156429,'f6': 0.1329005755644884, 'f7': 0.453691378873825, 'g1': 44}Best Score = -176159.62'''