結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 559 ms
43,580 KB
testcase_01 AC 576 ms
44,300 KB
testcase_02 AC 554 ms
43,976 KB
testcase_03 AC 317 ms
49,508 KB
testcase_04 AC 334 ms
49,752 KB
testcase_05 AC 319 ms
51,684 KB
testcase_06 AC 326 ms
49,844 KB
testcase_07 AC 292 ms
46,616 KB
testcase_08 AC 289 ms
48,080 KB
testcase_09 AC 327 ms
49,640 KB
testcase_10 AC 285 ms
48,456 KB
testcase_11 AC 271 ms
46,080 KB
testcase_12 AC 299 ms
49,940 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 604 ms
43,444 KB
testcase_19 AC 333 ms
51,344 KB
testcase_20 AC 571 ms
42,092 KB
testcase_21 AC 561 ms
43,588 KB
testcase_22 AC 543 ms
43,760 KB
testcase_23 AC 324 ms
50,908 KB
testcase_24 AC 278 ms
48,252 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

C = convolve(B,B)

print(C[X])
0