結果

問題 No.603 hel__world (2)
ユーザー maspymaspy
提出日時 2020-05-05 20:21:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,070 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 11,196 KB
実行使用メモリ 112,804 KB
最終ジャッジ日時 2023-09-09 09:37:30
合計ジャッジ時間 16,483 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
68,752 KB
testcase_01 AC 235 ms
68,352 KB
testcase_02 AC 235 ms
68,760 KB
testcase_03 AC 238 ms
68,832 KB
testcase_04 AC 238 ms
68,604 KB
testcase_05 AC 237 ms
68,352 KB
testcase_06 AC 125 ms
29,524 KB
testcase_07 AC 238 ms
68,488 KB
testcase_08 AC 240 ms
68,540 KB
testcase_09 AC 237 ms
68,708 KB
testcase_10 AC 236 ms
68,644 KB
testcase_11 AC 886 ms
86,804 KB
testcase_12 AC 875 ms
86,592 KB
testcase_13 AC 874 ms
86,752 KB
testcase_14 AC 232 ms
68,712 KB
testcase_15 WA -
testcase_16 AC 234 ms
68,616 KB
testcase_17 AC 235 ms
68,560 KB
testcase_18 AC 236 ms
68,484 KB
testcase_19 AC 236 ms
68,784 KB
testcase_20 AC 543 ms
77,536 KB
testcase_21 AC 551 ms
77,568 KB
testcase_22 AC 123 ms
29,400 KB
testcase_23 AC 242 ms
68,596 KB
testcase_24 AC 242 ms
68,436 KB
testcase_25 AC 895 ms
86,960 KB
testcase_26 WA -
testcase_27 AC 881 ms
86,560 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 388 ms
73,096 KB
testcase_31 AC 233 ms
68,680 KB
testcase_32 AC 562 ms
77,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**6 + 3

S = tuple(map(int, readline().split()))
T = tuple(x - ord('a') for x in read().rstrip())

L = [[] for _ in range(26)]
last_ch = -1
last_len = 0
for x in T:
    if x != last_ch:
        L[x].append(1)
    else:
        L[x][-1] += 1
    last_ch = x

def check_zero(S, L):
    for a in range(26):
        # if S[a] > 0 and (not L[a]):
        #     return True
        if S[a] < sum(L[a]):
            return True

if 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] %= MOD
    for n in range(1, Lsq):
        A[n] *= A[n - 1, -1]
        A[n] %= MOD
    return A.ravel()[:L]


def make_fact(U, MOD=MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = 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 = False
    fact_inv.flags.writeable = False
    return fact, fact_inv

fact, fact_inv = make_fact(MOD)

def compute(n, nums):
    if not nums:
        return 1
    nums = np.asarray(nums, np.int64)
    s = n - nums.sum()
    low = 0  # low * k 以下は全部とる
    high = 10**20
    for _ in range(100):
        x = (low + high) / 2
        a = np.floor(x * nums)
        if a.sum() <= s:
            low = x
        else:
            high = x
    n1 = nums + np.floor(low * nums).astype(np.int64)
    
    n2 = nums + np.floor(high * nums).astype(np.int64)
    I = np.where(n1 < n2)[0]
    r = n - n1.sum()
    n1[I[:r]] += 1
    n = n1
    k = nums
    # nCkの積を計算しよう
    n %= MOD
    if np.any(n < k):
        return 0
    x = fact[n] * fact_inv[k] * fact_inv[n - k] % MOD
    return cumprod(x)[-1]

x = 1
for n, nums in zip(S, L):
    x *= compute(n, nums)
    x %= MOD
print(x)

0