Submission #5031095


Source Code Expand

from functools import reduce
import math

def is_ok(t,h,A,B):
    cnt = 0 # 必要な攻撃回数
    for hp in h:
        cnt += max(0,math.ceil((hp-B*t)/(A-B)))
    if t >= cnt:
        return True
    else:
        return False

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,A,B = (int(_) for _ in input().split())
    h = []
    max_h = 0
    for i in range(N):
        h.append(int(input()))
        max_h = max(h[i],max_h)        
    ng = -1
    ok = math.ceil(max_h/B) # 考えうる最大の攻撃回数

    # 二分探索
    while (abs(ok-ng)>1):
        mid = (ok + ng) //2
        if is_ok(mid,h,A,B):
            ok = mid
        else:
            ng = mid
    print(ok)
    
if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task D - Widespread
User crewfanq
Language Python (3.4.3)
Score 400
Code Size 1844 Byte
Status AC
Exec Time 1445 ms
Memory 7616 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13
Case Name Status Exec Time Memory
a01 AC 22 ms 3572 KB
a02 AC 22 ms 3572 KB
a03 AC 23 ms 3572 KB
b04 AC 22 ms 3572 KB
b05 AC 276 ms 7608 KB
b06 AC 1445 ms 7616 KB
b07 AC 904 ms 7556 KB
b08 AC 860 ms 7612 KB
b09 AC 1370 ms 7616 KB
b10 AC 1134 ms 7576 KB
b11 AC 1162 ms 7572 KB
b12 AC 953 ms 7608 KB
b13 AC 1237 ms 7572 KB