結果
問題 | No.1043 直列大学 |
ユーザー | tpyneriver |
提出日時 | 2020-05-02 19:05:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 696 ms / 2,000 ms |
コード長 | 2,928 bytes |
コンパイル時間 | 1,481 ms |
コンパイル使用メモリ | 86,932 KB |
実行使用メモリ | 177,144 KB |
最終ジャッジ日時 | 2023-08-24 12:44:24 |
合計ジャッジ時間 | 10,449 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 106 ms
85,976 KB |
testcase_01 | AC | 105 ms
85,720 KB |
testcase_02 | AC | 106 ms
85,892 KB |
testcase_03 | AC | 106 ms
86,000 KB |
testcase_04 | AC | 106 ms
85,560 KB |
testcase_05 | AC | 106 ms
85,792 KB |
testcase_06 | AC | 105 ms
85,860 KB |
testcase_07 | AC | 106 ms
85,772 KB |
testcase_08 | AC | 105 ms
85,684 KB |
testcase_09 | AC | 137 ms
86,768 KB |
testcase_10 | AC | 154 ms
87,076 KB |
testcase_11 | AC | 196 ms
89,984 KB |
testcase_12 | AC | 696 ms
177,144 KB |
testcase_13 | AC | 439 ms
127,768 KB |
testcase_14 | AC | 484 ms
126,972 KB |
testcase_15 | AC | 551 ms
142,332 KB |
testcase_16 | AC | 465 ms
124,028 KB |
testcase_17 | AC | 228 ms
98,848 KB |
testcase_18 | AC | 279 ms
98,276 KB |
testcase_19 | AC | 426 ms
125,628 KB |
testcase_20 | AC | 231 ms
101,064 KB |
testcase_21 | AC | 420 ms
122,876 KB |
testcase_22 | AC | 412 ms
119,856 KB |
testcase_23 | AC | 632 ms
148,880 KB |
testcase_24 | AC | 309 ms
104,324 KB |
testcase_25 | AC | 413 ms
121,644 KB |
testcase_26 | AC | 487 ms
127,468 KB |
testcase_27 | AC | 216 ms
96,356 KB |
testcase_28 | AC | 273 ms
121,944 KB |
testcase_29 | AC | 118 ms
87,388 KB |
testcase_30 | AC | 431 ms
129,488 KB |
ソースコード
import sys from collections import Counter from operator import add readline = sys.stdin.readline MOD = 10**9+7 class Segtree: def __init__(self, A, intv, initialize = True, segf = max): self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf if initialize: self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N) for i in range(self.N0-1, 0, -1): self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) else: self.data = [intv]*(2*self.N0) def update(self, k, x): k += self.N0 self.data[k] = x while k > 0 : k = k >> 1 self.data[k] = self.segf(self.data[2*k], self.data[2*k+1]) def query(self, l, r): L, R = l+self.N0, r+self.N0 s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def binsearch(self, l, r, check, reverse = False): L, R = l+self.N0, r+self.N0 SL, SR = [], [] while L < R: if R & 1: R -= 1 SR.append(R) if L & 1: SL.append(L) L += 1 L >>= 1 R >>= 1 if reverse: for idx in (SR + SL[::-1]): if check(self.data[idx]): break else: return -1 while idx < self.N0: if check(self.data[2*idx+1]): idx = 2*idx + 1 else: idx = 2*idx return idx - self.N0 else: for idx in (SL + SR[::-1]): if check(self.data[idx]): break else: return -1 while idx < self.N0: if check(self.data[2*idx]): idx = 2*idx else: idx = 2*idx + 1 return idx - self.N0 N, M = map(int, readline().split()) V = list(map(int, readline().split())) R = list(map(int, readline().split())) A, B = map(int, readline().split()) limit = 10**5+2 tablev = Counter() tabler = Counter() tablev[0] = 1 tabler[0] = 1 for v in V: for k, val in tablev.copy().items(): tablev[v+k] += val for r in R: for k, val in tabler.copy().items(): tabler[r+k] += val tablev[0] = 0 tabler[0] = 0 TV = [0]*limit for i in range(limit): TV[i] = tablev[i] ans = 0 T = Segtree(TV, 0, initialize = True, segf = add) for k, v in tabler.items(): left, right = k*A, k*B left = min(left, limit) right = min(right, limit) + 1 ans = (ans + v*T.query(left, right))%MOD print(ans)