結果
問題 | No.603 hel__world (2) |
ユーザー |
![]() |
提出日時 | 2020-05-05 21:07:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,963 ms / 3,000 ms |
コード長 | 2,276 bytes |
コンパイル時間 | 225 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 126,756 KB |
最終ジャッジ日時 | 2024-06-27 04:07:35 |
合計ジャッジ時間 | 33,684 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import sysimport numpy as npread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesMOD = 10**6 + 3S = tuple(map(int, readline().split()))T = tuple(x - ord('a') for x in read().rstrip())L = [[] for _ in range(26)]last_ch = -1last_len = 0for x in T:if x != last_ch:L[x].append(1)else:L[x][-1] += 1last_ch = xdef check_zero(S, L):for a in range(26):# if S[a] > 0 and (not L[a]):# return Trueif S[a] < sum(L[a]):return Trueif check_zero(S, L):print(0)exit()def cumprod(A, MOD=MOD):L = len(A)Lsq = int(L**.5 + 1)A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)for n in range(1, Lsq):A[:, n] *= A[:, n - 1]A[:, n] %= MODfor n in range(1, Lsq):A[n] *= A[n - 1, -1]A[n] %= MODreturn A.ravel()[:L]def make_fact(U, MOD=MOD):x = np.arange(U, dtype=np.int64)x[0] = 1fact = cumprod(x, MOD)x = np.arange(U, 0, -1, dtype=np.int64)x[0] = pow(int(fact[-1]), MOD - 2, MOD)fact_inv = cumprod(x, MOD)[::-1]fact.flags.writeable = Falsefact_inv.flags.writeable = Falsereturn fact, fact_invfact, fact_inv = make_fact(MOD)def compute(n, nums):if not nums:return 1nums = np.asarray(nums, np.int64)s = n - nums.sum()low = 0 # low * k 以下は全部とるhigh = 2 * (10**18) // (nums.sum())for _ in range(200):x = (low + high) / 2a = np.floor(x * nums).astype(np.int64)if a.sum() <= s:low = xelse:high = xn1 = nums + np.floor(low * nums).astype(np.int64)n2 = nums + np.floor(high * nums).astype(np.int64)rest = n - n1.sum()I = np.where(n1 < n2)[0]r = n - n1.sum()n1[I[:r]] += 1r = n - n1.sum()for _ in range(r):c = np.min((n1 + 1) // nums)i = np.argmin((n1 + 1 - c * nums) / nums)n1[i] += 1n = n1k = nums# nCkの積を計算しようn %= MODif np.any(n < k):return 0x = fact[n] * fact_inv[k] * fact_inv[n - k] % MODreturn cumprod(x)[-1]x = 1for n, nums in zip(S, L):x *= compute(n, nums)x %= MODprint(x)