結果

問題 No.937 Ultra Sword
ユーザー maspymaspy
提出日時 2020-03-28 16:59:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 421 ms / 3,000 ms
コード長 867 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 23,468 KB
最終ジャッジ日時 2023-08-30 18:00:04
合計ジャッジ時間 16,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
16,120 KB
testcase_01 AC 262 ms
15,940 KB
testcase_02 AC 256 ms
15,964 KB
testcase_03 AC 261 ms
16,080 KB
testcase_04 AC 258 ms
16,032 KB
testcase_05 AC 312 ms
20,352 KB
testcase_06 AC 392 ms
21,552 KB
testcase_07 AC 410 ms
22,144 KB
testcase_08 AC 330 ms
19,116 KB
testcase_09 AC 315 ms
18,548 KB
testcase_10 AC 421 ms
22,560 KB
testcase_11 AC 281 ms
16,856 KB
testcase_12 AC 367 ms
20,120 KB
testcase_13 AC 367 ms
19,972 KB
testcase_14 AC 382 ms
20,608 KB
testcase_15 AC 349 ms
19,488 KB
testcase_16 AC 268 ms
15,840 KB
testcase_17 AC 273 ms
16,472 KB
testcase_18 AC 359 ms
19,888 KB
testcase_19 AC 313 ms
17,672 KB
testcase_20 AC 314 ms
17,852 KB
testcase_21 AC 417 ms
23,468 KB
testcase_22 AC 259 ms
15,948 KB
testcase_23 AC 266 ms
16,008 KB
testcase_24 AC 380 ms
20,396 KB
testcase_25 AC 332 ms
19,992 KB
testcase_26 AC 329 ms
19,308 KB
testcase_27 AC 324 ms
19,404 KB
testcase_28 AC 344 ms
19,576 KB
testcase_29 AC 257 ms
15,912 KB
testcase_30 AC 322 ms
18,044 KB
testcase_31 AC 348 ms
20,240 KB
testcase_32 AC 306 ms
17,952 KB
testcase_33 AC 350 ms
20,424 KB
testcase_34 AC 269 ms
16,864 KB
testcase_35 AC 264 ms
16,364 KB
testcase_36 AC 330 ms
19,696 KB
testcase_37 AC 258 ms
16,344 KB
testcase_38 AC 316 ms
19,068 KB
testcase_39 AC 259 ms
16,208 KB
testcase_40 AC 325 ms
19,644 KB
testcase_41 AC 276 ms
17,092 KB
testcase_42 AC 309 ms
18,004 KB
testcase_43 AC 308 ms
17,844 KB
testcase_44 AC 275 ms
17,076 KB
testcase_45 AC 289 ms
17,404 KB
testcase_46 AC 300 ms
17,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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)
0