結果
| 問題 |
No.937 Ultra Sword
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:26:51 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,434 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 116,436 KB |
| 最終ジャッジ日時 | 2025-03-20 20:28:21 |
| 合計ジャッジ時間 | 6,349 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 17 |
ソースコード
import sys
import math
from math import gcd
from functools import reduce
from collections import defaultdict
def main():
input = sys.stdin.read().split()
n = int(input[0])
A = list(map(int, input[1:n+1]))
if not A:
print(0)
return
current_gcd = A[0]
for num in A[1:]:
current_gcd = math.gcd(current_gcd, num)
G = current_gcd
total_sum = sum(A)
# Check if sum_g is achievable
sum_g = total_sum // G
sum_g_possible = False
# Check if G is present in the original array
if G in A:
sum_g_possible = True
else:
a_values = [num // G for num in A]
a_set = set(a_values)
for a in a_set:
if (a ^ 1) in a_set:
sum_g_possible = True
break
# Compute sum_after for all d in A
max_A = max(A)
freq = defaultdict(int)
for num in A:
freq[num] += 1
sum_div = [0] * (max_A + 1)
for d in range(1, max_A + 1):
for multiple in range(d, max_A + 1, d):
if multiple in freq:
sum_div[d] += (multiple // d) * freq[multiple]
unique_ds = list(freq.keys())
if not unique_ds:
print(0)
return
candidate_min = min(total_sum - sum_div[d] * (d - 1) for d in unique_ds)
answer = candidate_min
if sum_g_possible:
answer = min(answer, sum_g)
print(answer)
if __name__ == "__main__":
main()
lam6er