結果

問題 No.5018 Let's Make a Best-seller Book
ユーザー Kiri8128Kiri8128
提出日時 2023-10-02 03:40:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 400 ms
コード長 8,898 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 93,072 KB
スコア 163,196
平均クエリ数 52.00
最終ジャッジ日時 2023-10-02 03:40:49
合計ジャッジ時間 21,687 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
93,072 KB
testcase_01 AC 142 ms
92,156 KB
testcase_02 AC 132 ms
92,108 KB
testcase_03 AC 132 ms
92,620 KB
testcase_04 AC 132 ms
92,588 KB
testcase_05 AC 134 ms
92,364 KB
testcase_06 AC 136 ms
92,612 KB
testcase_07 AC 135 ms
92,500 KB
testcase_08 AC 139 ms
92,592 KB
testcase_09 AC 133 ms
92,260 KB
testcase_10 AC 133 ms
92,404 KB
testcase_11 AC 134 ms
92,284 KB
testcase_12 AC 134 ms
93,004 KB
testcase_13 AC 133 ms
92,924 KB
testcase_14 AC 138 ms
92,596 KB
testcase_15 AC 138 ms
92,392 KB
testcase_16 AC 135 ms
92,580 KB
testcase_17 AC 135 ms
92,964 KB
testcase_18 AC 140 ms
92,468 KB
testcase_19 AC 136 ms
92,508 KB
testcase_20 AC 136 ms
92,364 KB
testcase_21 AC 135 ms
92,272 KB
testcase_22 AC 141 ms
92,612 KB
testcase_23 AC 138 ms
92,904 KB
testcase_24 AC 134 ms
92,540 KB
testcase_25 AC 136 ms
92,396 KB
testcase_26 AC 134 ms
92,900 KB
testcase_27 AC 137 ms
92,660 KB
testcase_28 AC 137 ms
92,520 KB
testcase_29 AC 136 ms
93,036 KB
testcase_30 AC 137 ms
92,744 KB
testcase_31 AC 134 ms
92,672 KB
testcase_32 AC 136 ms
92,348 KB
testcase_33 AC 135 ms
92,116 KB
testcase_34 AC 137 ms
92,724 KB
testcase_35 AC 140 ms
93,032 KB
testcase_36 AC 137 ms
92,852 KB
testcase_37 AC 139 ms
92,372 KB
testcase_38 AC 137 ms
93,044 KB
testcase_39 AC 138 ms
92,452 KB
testcase_40 AC 137 ms
92,360 KB
testcase_41 AC 137 ms
92,060 KB
testcase_42 AC 143 ms
92,232 KB
testcase_43 AC 135 ms
92,716 KB
testcase_44 AC 138 ms
92,288 KB
testcase_45 AC 139 ms
92,372 KB
testcase_46 AC 135 ms
92,516 KB
testcase_47 AC 134 ms
92,760 KB
testcase_48 AC 137 ms
92,392 KB
testcase_49 AC 138 ms
92,496 KB
testcase_50 AC 138 ms
92,392 KB
testcase_51 AC 141 ms
92,400 KB
testcase_52 AC 140 ms
92,920 KB
testcase_53 AC 138 ms
92,356 KB
testcase_54 AC 139 ms
92,268 KB
testcase_55 AC 141 ms
92,884 KB
testcase_56 AC 136 ms
92,340 KB
testcase_57 AC 139 ms
92,772 KB
testcase_58 AC 135 ms
92,540 KB
testcase_59 AC 138 ms
92,636 KB
testcase_60 AC 141 ms
92,516 KB
testcase_61 AC 141 ms
92,236 KB
testcase_62 AC 139 ms
92,204 KB
testcase_63 AC 135 ms
92,324 KB
testcase_64 AC 140 ms
92,268 KB
testcase_65 AC 139 ms
92,876 KB
testcase_66 AC 139 ms
92,612 KB
testcase_67 AC 138 ms
92,648 KB
testcase_68 AC 138 ms
92,348 KB
testcase_69 AC 138 ms
92,852 KB
testcase_70 AC 138 ms
92,864 KB
testcase_71 AC 138 ms
92,232 KB
testcase_72 AC 137 ms
92,672 KB
testcase_73 AC 141 ms
92,788 KB
testcase_74 AC 141 ms
92,596 KB
testcase_75 AC 143 ms
92,308 KB
testcase_76 AC 139 ms
92,808 KB
testcase_77 AC 138 ms
92,896 KB
testcase_78 AC 139 ms
92,304 KB
testcase_79 AC 139 ms
92,596 KB
testcase_80 AC 138 ms
92,420 KB
testcase_81 AC 139 ms
92,284 KB
testcase_82 AC 140 ms
92,836 KB
testcase_83 AC 137 ms
92,376 KB
testcase_84 AC 137 ms
92,656 KB
testcase_85 AC 136 ms
92,000 KB
testcase_86 AC 136 ms
92,336 KB
testcase_87 AC 139 ms
92,724 KB
testcase_88 AC 140 ms
92,680 KB
testcase_89 AC 140 ms
92,456 KB
testcase_90 AC 136 ms
92,436 KB
testcase_91 AC 140 ms
92,836 KB
testcase_92 AC 141 ms
92,312 KB
testcase_93 AC 139 ms
92,404 KB
testcase_94 AC 139 ms
92,312 KB
testcase_95 AC 141 ms
92,724 KB
testcase_96 AC 139 ms
92,472 KB
testcase_97 AC 138 ms
92,604 KB
testcase_98 AC 136 ms
92,296 KB
testcase_99 AC 141 ms
92,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import gauss, random, randrange

try:
    LOCAL
except NameError:
    LOCAL = 0

if LOCAL:
    import optuna
    DEBUG = 1
    print("LOOP ?")
    LOOP = int(input())
else:
    DEBUG = 0
    LOOP = 1

def receive():
    global P
    global R
    global money
    global MI, MA
    global sell_count
    if 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 3
    if n % 10 < 3:
        return n // 10 * 10
    if n % 10 < 6:
        return n // 10 * 10 + 3
    return n // 10 * 10 + 6
    
def Order(f1, f2, f3, f4, f5, f6, f7, g1):
    global P
    global R
    global money
    global best_allocation_flg
    target = 10
    buy_count = [0] * N
    
    best_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 ** 8
        best_allocation[i] = adj(int(best_allocation[i]))
    best_allocation_flg = [0] * N
    for i in range(N):
        if t == 0:
            target = 3
        elif t < 5:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.0 + MI[i] * 1.0)) ** 2 * f1))
        elif t < 12:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f2))
        elif t < 20:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f3))
        elif t < 30 and P[i] < g1:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f4))
        elif t < 40 and P[i] < g1:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f5))
        elif t < 45 and P[i] < g1:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f6))
        elif t < 49 and P[i] < g1:
            target = adj(int((10 / 3 * 1.05 ** P[i] * (MA[i] * 0.5 + MI[i] * 0.5)) ** 2 * f7))
        elif t < 100:
            target = best_allocation[i]
            best_allocation_flg[i] = 1
        else:
            assert 0
        buy_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 / money
        if r <= 1:
            break
        
        
        for i in range(N):
            buy_count[i] = adj(int(buy_count[i] / r))
    
    money -= sum(buy_count) * 500
    if money < 0:
        while 1:
            pass
    assert money >= 0
    for i in range(N):
        R[i] += buy_count[i]
    if not DEBUG:
        print(1, *buy_count)
    
def Advertise(x):
    global money
    money -= 500000 << x - 1
    if money < 0:
        while 1:
            pass
    assert money >= 0
    for 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):
    global T, N, money
    global MI, MA, P, R, t, D, total_sell_count, LOOP
    global total_total
    ret = 0
    main_loop_loop = 1000
    for _ 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)
    return ret / main_loop_loop
def main(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1):
    global T, N, money
    global MI, MA, P, R, t, D, total_sell_count, LOOP
    global total_total
    if DEBUG:
        T, N, money = 52, 10, 2 * 10 ** 6
        D = [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] * N
    sell_count = [0] * N
    best_allocation_flg = [0] * N
    MA = [1.5] * N
    MI = [0.5] * N
    P = [0] * N
    R = [0] * N
    for 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)
        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, 10)
    adv_r2 = trial.suggest_int('adv_r2', 25, 45)
    adv_m2 = trial.suggest_float('adv_m2', 105 * 10 ** 4, 150 * 10 ** 4)
    adv_l3 = trial.suggest_int('adv_l3', 10, 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.55, 0.90)
    f2 = trial.suggest_float('f2', 0.35, 0.70)
    f3 = trial.suggest_float('f3', 0.20, 0.60)
    f4 = trial.suggest_float('f4', 0.10, 0.60)
    f5 = trial.suggest_float('f5', 0.10, 0.50)
    f6 = trial.suggest_float('f6', 0.05, 0.50)
    f7 = trial.suggest_float('f7', 0.05, 0.50)
    g1 = trial.suggest_int('g1', 40, 60)
    score = main_loop(adv_l2, adv_r2, adv_m2, adv_l3, adv_r3, adv_m3, f1, f2, f3, f4, f5, f6, f7, g1)
    return -score


OP = 0
if OP:
    T, N, money = None, None, None
    MI, MA, D = None, None, None
    P, R, t, total_sell_count = None, None, None, None
    study = optuna.create_study()
    study.optimize(objective, n_trials=200)
    print("Best Params =", study.best_params)
    print("Best Score =", study.best_value)
else:
    total_total = 0
    _t = 0
    for loop in range(LOOP):
        _t += main(1, 34, 1070000, 18, 39, 2510000, 0.753, 0.578, 0.400, 0.529, 0.490, 0.393, 
                   0.216, 50)
    if LOCAL:
        print("LOOP =", LOOP, round(total_total / LOOP), round(_t / LOOP))

_ = '''
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.633


Best 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
'''
0