結果

問題 No.723 2つの数の和
ユーザー rkato5680rkato5680
提出日時 2021-02-12 16:18:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 51,360 KB
最終ジャッジ日時 2023-09-26 15:13:49
合計ジャッジ時間 9,445 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 295 ms
29,700 KB
testcase_01 AC 287 ms
29,756 KB
testcase_02 AC 335 ms
29,672 KB
testcase_03 AC 305 ms
47,944 KB
testcase_04 AC 323 ms
49,756 KB
testcase_05 AC 326 ms
49,960 KB
testcase_06 AC 325 ms
49,340 KB
testcase_07 AC 288 ms
48,440 KB
testcase_08 AC 301 ms
49,836 KB
testcase_09 AC 330 ms
50,572 KB
testcase_10 AC 300 ms
48,460 KB
testcase_11 AC 270 ms
45,528 KB
testcase_12 AC 292 ms
50,204 KB
testcase_13 AC 330 ms
50,544 KB
testcase_14 AC 280 ms
46,076 KB
testcase_15 AC 289 ms
46,932 KB
testcase_16 AC 305 ms
47,596 KB
testcase_17 AC 320 ms
51,360 KB
testcase_18 AC 339 ms
31,328 KB
testcase_19 AC 319 ms
50,996 KB
testcase_20 AC 285 ms
29,792 KB
testcase_21 AC 288 ms
29,772 KB
testcase_22 AC 284 ms
29,596 KB
testcase_23 AC 326 ms
51,196 KB
testcase_24 AC 274 ms
46,916 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,pad=True):
    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
    if pad:
      return np.trim_zeros((irfft(rfft(b1)*rfft(b2))+0.5).astype(int), 'b')
    else:
      return (irfft(rfft(b1)*rfft(b2))+0.5).astype(int)

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] if X < len(C) else 0)
0