結果

問題 No.1238 選抜クラス
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-09-26 10:38:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,607 ms / 2,000 ms
コード長 5,675 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 13,440 KB
実行使用メモリ 45,040 KB
最終ジャッジ日時 2024-06-28 20:29:33
合計ジャッジ時間 40,862 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 541 ms
44,788 KB
testcase_01 AC 553 ms
44,788 KB
testcase_02 AC 612 ms
44,648 KB
testcase_03 AC 535 ms
44,780 KB
testcase_04 AC 540 ms
44,656 KB
testcase_05 AC 536 ms
44,536 KB
testcase_06 AC 542 ms
44,788 KB
testcase_07 AC 583 ms
45,036 KB
testcase_08 AC 609 ms
44,788 KB
testcase_09 AC 666 ms
44,916 KB
testcase_10 AC 584 ms
44,528 KB
testcase_11 AC 649 ms
44,652 KB
testcase_12 AC 624 ms
44,524 KB
testcase_13 AC 622 ms
44,656 KB
testcase_14 AC 611 ms
44,788 KB
testcase_15 AC 668 ms
44,820 KB
testcase_16 AC 650 ms
44,676 KB
testcase_17 AC 1,487 ms
44,660 KB
testcase_18 AC 1,407 ms
44,528 KB
testcase_19 AC 1,464 ms
44,524 KB
testcase_20 AC 1,442 ms
44,656 KB
testcase_21 AC 1,381 ms
44,656 KB
testcase_22 AC 1,459 ms
44,524 KB
testcase_23 AC 1,485 ms
44,784 KB
testcase_24 AC 1,477 ms
44,652 KB
testcase_25 AC 1,520 ms
44,528 KB
testcase_26 AC 1,500 ms
44,780 KB
testcase_27 AC 1,561 ms
44,780 KB
testcase_28 AC 1,467 ms
44,836 KB
testcase_29 AC 1,607 ms
44,652 KB
testcase_30 AC 833 ms
44,780 KB
testcase_31 AC 1,032 ms
44,536 KB
testcase_32 AC 1,260 ms
44,524 KB
testcase_33 AC 580 ms
44,536 KB
testcase_34 AC 1,323 ms
44,652 KB
testcase_35 AC 887 ms
44,908 KB
testcase_36 AC 704 ms
45,040 KB
testcase_37 AC 846 ms
44,648 KB
testcase_38 AC 1,393 ms
44,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random
#Union-Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.par = [-1 for i in range(self.n)]
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.par[p] += self.par[q]
        self.par[q] = p
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]

#素数関連
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
def is_prime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime_number = 7
    difference = 4
    while prime_number <= math.sqrt(x):
        if x % prime_number == 0:
            return False
        prime_number += difference
        difference = 6 - difference
    return True
#Prime-Factorize
def prime_factorize(n):
    res = []
    while n % 2 == 0:
        res.append(2)
        n //= 2
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            res.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        res.append(n)
    return res
#nCr
mod = 10 ** 9 + 7
class nCr():
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
#拡張Euclidの互除法
def extgcd(a, b, d = 0):
    g = a
    if b == 0:
        x, y = 1, 0
    else:
        x, y, g = extgcd(b, a % b)
        x, y = y, x - a // b * y
    return x, y, g
#BIT
class BinaryIndexedTree():
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (self.n + 1)
    def add(self, i, x):
        while i <= self.n:
            self.BIT[i] += x
            i += i & -i
    def query(self, i):
        res = 0
        while i > 0:
            res += self.BIT[i]
            i -= i & -i
        return res
#Associative Array
class AssociativeArray():
    def __init__(self, q):
        self.dic = dict()
        self.q = q
    def solve(self):
        for i in range(self.q):
            Query = list(map(int, input().split()))
            if Query[0] == 0:
                x, y, z = Query
                self.dic[y] = z
            else:
                x, y = Query
                if y in self.dic:
                    print(self.dic[y])
                else:
                    print(0)
#Floor Sum
def floor_sum(n, m, a, b):
    res = 0
    if a >= m:
        res += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        res += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return res
    res += y_max * (n + (-x_max // a))
    res += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return res
#Z-Algorithm
def z_algorithm(s):
    str_len = len(s)
    res = [0] * str_len
    res[str_len - 1] = str_len
    i, j = 1, 0
    while i < str_len:
        while i + j < str_len and s[i + j] == s[j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < str_len and j > res[k] + k:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res
class Manacher():
    def __init__(self, s):
        self.s = s
    def coustruct(self):
        i, j = 0, 0 
        s_len = len(self.s)
        res = [0] * s_len
        while i < s_len:
            while i - j >= 0 and i + j < s_len and self.s[i - j] == self.s[i + j]:
                j += 1
            res[i] = j
            k = 1
            while i - k >= 0 and k + res[i - k] < j:
                k += 1
            i += k
            j -= k
#mod-sqrt
def mod_sqrt(a, p):
    if a == 0:
        return 0
    if p == 2:
        return 1
    k = (p - 1) // 2
    if pow(a, k, p) != 1:
        return -1
    while True:
        n = random.randint(2, p - 1)
        r = (n ** 2 - a) % p
        if r == 0:
            return n
        if pow(r, k, p) == p - 1:
            break
    k += 1
    w, x, y, z = n, 1, 1, 0
    while k:
        if k % 2:
            y, z = w * y + r * x * z, x * y + w * z
        w, x = w * w + r * x * x, 2 * w * x
        w %= p
        x %= p
        y %= p
        z %= p
        k >>= 1
    return y
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x - k, a))
mod = 10 ** 9 + 7
dp = [0] * 20001
dp[10000] = 1
for i in a:
    new = dp[:]
    for j in range(20001):
        if 0 <= i + j <= 20000:
            new[i + j] += dp[j]
            new[i + j] %= mod
    dp = new
print((sum(dp[10000:]) - 1) % mod)
0