結果
| 問題 |
No.937 Ultra Sword
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-28 16:59:12 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 563 ms / 3,000 ms |
| コード長 | 867 bytes |
| コンパイル時間 | 341 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 25,316 KB |
| 最終ジャッジ日時 | 2025-01-02 11:48:34 |
| 合計ジャッジ時間 | 21,848 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce
U = 10 ** 5
N, *A = map(int, read().split())
num_count = [0] * (U + 1)
for x in A:
num_count[x] += 1
save_cost = [0] * (U + 1)
for d in range(2, U + 1):
save_cost[d] = sum((n - n // d) * num_count[n] for n in range(d, U + 1, d))
def gcd(a, b):
if a < b:
a, b = b, a
while b:
LA = a.bit_length()
LB = b.bit_length()
a ^= b << (LA - LB)
if a < b:
a, b = b, a
return a
g = reduce(gcd, A)
cand = [0]
for i in range(17):
cand += [x ^ (g << i) for x in cand]
max_save = 0
for d in cand:
if 1 <= d <= U:
x = save_cost[d]
if max_save < x:
max_save = x
answer = sum(A) - max_save
print(answer)
maspy