結果

問題 No.723 2つの数の和
ユーザー rkato5680rkato5680
提出日時 2021-02-12 16:15:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,234 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 52,576 KB
最終ジャッジ日時 2023-09-26 15:10:57
合計ジャッジ時間 9,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
29,632 KB
testcase_01 AC 298 ms
29,696 KB
testcase_02 AC 297 ms
29,568 KB
testcase_03 AC 324 ms
49,320 KB
testcase_04 AC 334 ms
49,292 KB
testcase_05 AC 325 ms
52,576 KB
testcase_06 AC 332 ms
51,164 KB
testcase_07 AC 292 ms
48,496 KB
testcase_08 AC 294 ms
47,316 KB
testcase_09 AC 344 ms
51,400 KB
testcase_10 AC 292 ms
47,496 KB
testcase_11 AC 270 ms
46,932 KB
testcase_12 AC 296 ms
48,884 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 336 ms
31,492 KB
testcase_19 AC 318 ms
50,092 KB
testcase_20 AC 288 ms
29,500 KB
testcase_21 AC 293 ms
29,828 KB
testcase_22 AC 288 ms
29,544 KB
testcase_23 AC 321 ms
50,064 KB
testcase_24 AC 277 ms
49,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 一体版
import numpy as np
from numpy.fft import rfft,irfft

def add(A,B):
    if len(A)<len(B): A,B = B,A
    out = A[:]
    for i in range(-1,-len(B)-1,-1):
        out[i] += B[i]
    return out

def convolve(a1,a2):
    n = 2**(len(a1)+len(a2)+1).bit_length()
    b1,b2=np.zeros(n),np.zeros(n)
    b1[:len(a1)], b2[:len(a2)]= a1,a2
    return np.trim_zeros((irfft(rfft(b1)*rfft(b2))+0.5).astype(int), 'b')

def power(A, k):
    nzero = len(A)-len(np.trim_zeros(A,"f"))
    coef = [A[::-1]]
    out = [1]
    for i in range(k.bit_length()):
        coef.append(convolve(coef[-1], coef[-1]))
        if (k>>i)&1:
            out = convolve(out, coef[-2])
    return np.hstack([np.zeros(nzero*k,dtype=int),out[::-1]])

def div(A, B):
    Q = []
    for i in range(max(len(A)-len(B)+1, 0)):
        Q.append(A[i] /B[0])
        for j in range(len(B)):
            A[i+j] -= Q[-1]*B[j]
    R = []
    for i in range(len(A)):
        if A[i]: 
            R = A[i:]
            break
    if not Q: Q = [0]
    if not R: R = [0]
    return Q,R
  
N,X = map(int,input().split())
*A,=map(int,input().split())

B = np.zeros(10**5+5,dtype=int)

for i in range(N):
  B[A[i]] += 1
  
B = np.trim_zeros(B,"b")

C = convolve(B,B)

print(C[X])
0