結果

問題 No.937 Ultra Sword
ユーザー vwxyzvwxyz
提出日時 2023-11-29 20:22:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 279 ms / 3,000 ms
コード長 2,574 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 106,496 KB
最終ジャッジ日時 2024-09-26 13:37:08
合計ジャッジ時間 11,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
89,600 KB
testcase_01 AC 196 ms
90,368 KB
testcase_02 AC 165 ms
89,344 KB
testcase_03 AC 166 ms
89,472 KB
testcase_04 AC 163 ms
89,472 KB
testcase_05 AC 197 ms
106,496 KB
testcase_06 AC 256 ms
101,120 KB
testcase_07 AC 261 ms
102,528 KB
testcase_08 AC 247 ms
94,336 KB
testcase_09 AC 248 ms
92,544 KB
testcase_10 AC 279 ms
104,832 KB
testcase_11 AC 210 ms
90,752 KB
testcase_12 AC 237 ms
101,760 KB
testcase_13 AC 241 ms
101,760 KB
testcase_14 AC 238 ms
103,680 KB
testcase_15 AC 233 ms
98,944 KB
testcase_16 AC 203 ms
90,752 KB
testcase_17 AC 202 ms
90,496 KB
testcase_18 AC 218 ms
100,480 KB
testcase_19 AC 200 ms
95,232 KB
testcase_20 AC 205 ms
93,568 KB
testcase_21 AC 278 ms
104,960 KB
testcase_22 AC 187 ms
89,728 KB
testcase_23 AC 188 ms
89,472 KB
testcase_24 AC 249 ms
104,832 KB
testcase_25 AC 216 ms
103,040 KB
testcase_26 AC 216 ms
99,584 KB
testcase_27 AC 216 ms
99,968 KB
testcase_28 AC 222 ms
100,992 KB
testcase_29 AC 188 ms
90,368 KB
testcase_30 AC 212 ms
97,536 KB
testcase_31 AC 225 ms
104,832 KB
testcase_32 AC 206 ms
97,280 KB
testcase_33 AC 218 ms
104,960 KB
testcase_34 AC 198 ms
90,624 KB
testcase_35 AC 188 ms
90,496 KB
testcase_36 AC 219 ms
102,400 KB
testcase_37 AC 195 ms
90,624 KB
testcase_38 AC 209 ms
99,584 KB
testcase_39 AC 187 ms
90,496 KB
testcase_40 AC 211 ms
101,120 KB
testcase_41 AC 196 ms
93,184 KB
testcase_42 AC 208 ms
98,176 KB
testcase_43 AC 207 ms
97,280 KB
testcase_44 AC 194 ms
91,264 KB
testcase_45 AC 200 ms
93,696 KB
testcase_46 AC 203 ms
93,824 KB
権限があれば一括ダウンロードができます

ソースコード

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)
C=[0]*(max_A+1)
for a in A:
    C[a]+=1
sum_A=sum(A)
g=A[0]
for a in A[1:]:
    if a>g:
        a,g=g,a
    while a:
        g^=a<<(g.bit_length()-a.bit_length())
        if a>g:
            a,g=g,a
ans=sum_A
for i in range(1,max_A+1):
    ii=i
    while ii>=g:
        ii^=g<<(ii.bit_length()-g.bit_length())
    if ii==0:
        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