結果

問題 No.937 Ultra Sword
ユーザー vwxyzvwxyz
提出日時 2023-11-29 19:34:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,615 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 112,512 KB
最終ジャッジ日時 2024-09-26 13:35:38
合計ジャッジ時間 17,455 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
89,728 KB
testcase_01 AC 388 ms
98,432 KB
testcase_02 AC 166 ms
89,600 KB
testcase_03 AC 166 ms
89,600 KB
testcase_04 AC 170 ms
89,984 KB
testcase_05 AC 370 ms
112,000 KB
testcase_06 AC 427 ms
108,800 KB
testcase_07 AC 430 ms
110,208 KB
testcase_08 AC 418 ms
102,400 KB
testcase_09 AC 417 ms
100,736 KB
testcase_10 AC 433 ms
112,384 KB
testcase_11 AC 206 ms
90,880 KB
testcase_12 AC 223 ms
101,120 KB
testcase_13 AC 227 ms
101,376 KB
testcase_14 AC 225 ms
102,912 KB
testcase_15 AC 220 ms
98,560 KB
testcase_16 AC 201 ms
90,624 KB
testcase_17 AC 212 ms
90,624 KB
testcase_18 AC 223 ms
99,968 KB
testcase_19 AC 212 ms
94,848 KB
testcase_20 AC 213 ms
93,568 KB
testcase_21 AC 431 ms
112,512 KB
testcase_22 WA -
testcase_23 RE -
testcase_24 AC 366 ms
112,256 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
#sys.set_int_max_str_digits(10**9)

def Hadamard(polynomial,n,mod=0,inverse=False):
    assert mod%2
    polynomial_=[x for x in polynomial]+[0]*((1<<n)-len(polynomial))
    for bit in range(n):
        for i in range(1<<n):
            ii=i^(1<<bit)
            if i>ii:
                continue
            polynomial_[i],polynomial_[ii]=polynomial_[i]+polynomial_[ii],polynomial_[i]-polynomial_[ii]
            if mod:
                polynomial_[i]%=mod
                polynomial_[ii]%=mod
    if inverse:
        if mod:
            inve_2=pow((mod+1)//2,n)
            for i in range(1<<n):
                polynomial_[i]*=inve_2
                polynomial_[i]%=mod
        else:
            pow_2=pow(2,n)
            for i in range(1<<n):
                polynomial_[i]/=pow_2
    return polynomial_

def XOR_Convolution(polynomial0,polynomial1,mod=0):
    n=(max(len(polynomial0),len(polynomial1))-1).bit_length()
    Hadamard_polynomial0=Hadamard(polynomial0,n,mod=mod)
    Hadamard_polynomial1=Hadamard(polynomial1,n,mod=mod)
    if mod:
        convolution=[x*y%mod for x,y in zip(Hadamard_polynomial0,Hadamard_polynomial1)]
    else:
        convolution=[x*y for x,y in zip(Hadamard_polynomial0,Hadamard_polynomial1)]
    convolution=Hadamard(convolution,n,mod=mod,inverse=True)
    return convolution

N=int(readline())
A=list(map(int,readline().split()))
max_A=max(A)
le=max_A.bit_length()
poly=[0]*(1<<le)
poly[0]=1
for a in A:
    while a<1<<le:
        poly[a]=1
        a*=2
mod=(1<<61)-1
poly=Hadamard(poly,le,mod=mod)
for i in range(30):
    poly[i]=pow(poly[i],10**9,mod)
poly=Hadamard(poly,le,mod=mod,inverse=True)
C=[0]*(max_A+1)
for a in A:
    C[a]+=1
sum_A=sum(A)
ans=sum_A
for i in range(1,max_A+1):
    if poly[i]==0:
        continue
    s=sum_A
    for j in range(i,max_A+1,i):
        s-=C[j]*(j-j//i)
    ans=min(ans,s)
print(ans)
0