結果

問題 No.1043 直列大学
ユーザー w0mbatw0mbat
提出日時 2020-05-01 23:04:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 2,799 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 132,164 KB
最終ジャッジ日時 2023-08-24 05:52:31
合計ジャッジ時間 6,927 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,812 KB
testcase_01 AC 81 ms
76,932 KB
testcase_02 AC 84 ms
77,028 KB
testcase_03 AC 82 ms
77,288 KB
testcase_04 AC 84 ms
76,988 KB
testcase_05 AC 83 ms
76,752 KB
testcase_06 AC 82 ms
76,992 KB
testcase_07 AC 83 ms
76,900 KB
testcase_08 AC 84 ms
77,032 KB
testcase_09 AC 123 ms
77,740 KB
testcase_10 AC 138 ms
79,300 KB
testcase_11 AC 247 ms
91,272 KB
testcase_12 AC 379 ms
132,164 KB
testcase_13 AC 230 ms
95,652 KB
testcase_14 AC 264 ms
104,156 KB
testcase_15 AC 320 ms
111,432 KB
testcase_16 AC 246 ms
103,600 KB
testcase_17 AC 134 ms
79,204 KB
testcase_18 AC 154 ms
84,716 KB
testcase_19 AC 232 ms
96,304 KB
testcase_20 AC 136 ms
80,176 KB
testcase_21 AC 226 ms
97,564 KB
testcase_22 AC 213 ms
92,796 KB
testcase_23 AC 361 ms
125,180 KB
testcase_24 AC 153 ms
81,868 KB
testcase_25 AC 205 ms
89,368 KB
testcase_26 AC 261 ms
102,004 KB
testcase_27 AC 123 ms
79,068 KB
testcase_28 AC 189 ms
83,240 KB
testcase_29 AC 101 ms
77,148 KB
testcase_30 AC 189 ms
91,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    V=map(int, input().split())
    R=map(int, input().split())
    A,B=map(int, input().split())

    dV=[0]*(1000*100+1)
    dV[0]=1
    for v in V:
        for i in range(1000*100+1,-1,-1):
            if i+v>1000*100: continue
            dV[i+v]+=dV[i]
    dR=[0]*(1000*100+1)
    dR[0]=1
    for r in R:
        for i in range(1000*100+1,-1,-1):
            if i+r>1000*100: continue
            dR[i+r]+=dR[i]
    for i in range(1,1000*100+1):
        dV[i]+=dV[i-1]
    ans=Mint()
    for i in range(1,1000*100+1):
        r=dR[i]
        if r>0:
            a=min(1000*100,i*A)
            b=min(1000*100,i*B)
            ans+=r*(dV[b]-dV[a-1])
    print(ans)

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other)) % MOD
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    main()
0