結果
問題 |
No.937 Ultra Sword
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:52:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,425 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 52,480 KB |
最終ジャッジ日時 | 2025-06-12 13:54:11 |
合計ジャッジ時間 | 5,563 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 3 TLE * 1 -- * 41 |
ソースコード
import sys import math def main(): n, *rest = map(int, sys.stdin.read().split()) a = rest[:n] sum_total = sum(a) # Compute GCD of all elements g = a[0] for num in a[1:]: g = math.gcd(g, num) # Check if GCD can be generated via magic s = set(a) can_generate = False # Check XOR condition for num in a: xor_val = num ^ g if xor_val in s and xor_val != num: can_generate = True break # Check doubling condition if not can_generate: for num in a: if g % num != 0: continue q = g // num # Check if q is a power of two if (q & (q - 1)) == 0 and q != 0: can_generate = True break sum_candidate = sum_total // g if can_generate else float('inf') # Compute minimal sum when using original elements min_original = float('inf') for x in a: current_sum = 1 # x becomes 1 for num in a: if num == x: continue if num % x == 0: current_sum += num // x else: current_sum += num if current_sum < min_original: min_original = current_sum # Determine the answer answer = min(sum_candidate, min_original) print(answer) if __name__ == '__main__': main()