結果
問題 |
No.937 Ultra Sword
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:34:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,030 bytes |
コンパイル時間 | 244 ms |
コンパイル使用メモリ | 82,640 KB |
実行使用メモリ | 103,292 KB |
最終ジャッジ日時 | 2025-06-12 21:36:14 |
合計ジャッジ時間 | 5,439 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 40 |
ソースコード
import math from math import gcd from functools import reduce from collections import defaultdict def compute_gcd(arr): return reduce(lambda x, y: gcd(x, y), arr) def get_divisors(n): if n == 0: return [] divisors = set() for i in range(1, int(math.sqrt(n)) + 1): if n % i == 0: divisors.add(i) divisors.add(n // i) return sorted(divisors) def main(): import sys input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:N+1])) if N == 0: print(0) return current_gcd = A[0] for num in A[1:]: current_gcd = gcd(current_gcd, num) divisors = get_divisors(current_gcd) freq = defaultdict(int) for num in A: freq[num] += 1 min_sum = float('inf') for x in divisors: s = 0 for y in freq: s += (y // x) * freq[y] if s < min_sum: min_sum = s print(min_sum) if __name__ == '__main__': main()