結果

問題 No.937 Ultra Sword
ユーザー lam6er
提出日時 2025-03-31 17:49:58
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 974 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 55,296 KB
最終ジャッジ日時 2025-03-31 17:50:43
合計ジャッジ時間 6,105 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from functools import reduce

def compute_gcd(arr):
    return reduce(math.gcd, arr)

def main():
    import sys
    input = sys.stdin.read().split()
    n = int(input[0])
    a = list(map(int, input[1:n+1]))
    sum_a = sum(a)
    if n == 0:
        print(0)
        return
    
    if all(x == 0 for x in a):
        print(0)
        return
    
    g = compute_gcd(a)
    
    min_original = float('inf')
    for i in range(n):
        d = a[i]
        current = 1
        for j in range(n):
            if i == j:
                continue
            x = a[j]
            if d == 0:
                current += x
            else:
                if x % d == 0:
                    current += x // d
                else:
                    current += x
        if current < min_original:
            min_original = current
    
    sum_created = sum_a // g
    answer = min(min_original, sum_created)
    print(answer)

if __name__ == "__main__":
    main()
0