結果

問題 No.295 hel__world
ユーザー maspymaspy
提出日時 2020-05-04 13:44:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 352 ms / 5,000 ms
コード長 1,945 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 27,864 KB
最終ジャッジ日時 2023-09-06 13:21:34
合計ジャッジ時間 5,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,776 KB
testcase_01 AC 21 ms
8,740 KB
testcase_02 AC 21 ms
8,704 KB
testcase_03 AC 21 ms
8,800 KB
testcase_04 AC 20 ms
8,856 KB
testcase_05 AC 21 ms
8,756 KB
testcase_06 AC 20 ms
8,704 KB
testcase_07 AC 20 ms
8,748 KB
testcase_08 AC 21 ms
8,884 KB
testcase_09 AC 21 ms
8,804 KB
testcase_10 AC 22 ms
8,812 KB
testcase_11 AC 20 ms
8,724 KB
testcase_12 AC 20 ms
8,748 KB
testcase_13 AC 21 ms
8,700 KB
testcase_14 AC 21 ms
8,772 KB
testcase_15 AC 20 ms
8,740 KB
testcase_16 AC 20 ms
8,908 KB
testcase_17 AC 20 ms
8,732 KB
testcase_18 AC 21 ms
8,728 KB
testcase_19 AC 20 ms
8,852 KB
testcase_20 AC 21 ms
8,704 KB
testcase_21 AC 20 ms
8,724 KB
testcase_22 AC 21 ms
8,724 KB
testcase_23 AC 21 ms
8,808 KB
testcase_24 AC 20 ms
8,884 KB
testcase_25 AC 35 ms
8,764 KB
testcase_26 AC 38 ms
8,728 KB
testcase_27 AC 21 ms
8,728 KB
testcase_28 AC 21 ms
8,732 KB
testcase_29 AC 25 ms
8,788 KB
testcase_30 AC 21 ms
8,728 KB
testcase_31 AC 20 ms
8,856 KB
testcase_32 AC 317 ms
27,268 KB
testcase_33 AC 314 ms
27,560 KB
testcase_34 AC 311 ms
27,864 KB
testcase_35 AC 20 ms
8,772 KB
testcase_36 AC 20 ms
8,780 KB
testcase_37 AC 21 ms
8,808 KB
testcase_38 AC 20 ms
8,700 KB
testcase_39 AC 20 ms
8,816 KB
testcase_40 AC 21 ms
8,800 KB
testcase_41 AC 20 ms
8,808 KB
testcase_42 AC 20 ms
8,744 KB
testcase_43 AC 20 ms
8,892 KB
testcase_44 AC 21 ms
8,816 KB
testcase_45 AC 20 ms
8,904 KB
testcase_46 AC 20 ms
8,748 KB
testcase_47 AC 21 ms
8,856 KB
testcase_48 AC 21 ms
8,724 KB
testcase_49 AC 20 ms
8,732 KB
testcase_50 AC 26 ms
8,888 KB
testcase_51 AC 20 ms
8,856 KB
testcase_52 AC 21 ms
8,780 KB
testcase_53 AC 352 ms
19,472 KB
testcase_54 AC 327 ms
19,392 KB
testcase_55 AC 348 ms
19,384 KB
testcase_56 AC 331 ms
19,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from functools import lru_cache
import itertools

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

INF = 2**62

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()

@lru_cache(None)
def comb(n, k):
    if k < 0 or k > n:
        return 0
    k = min(k, n - k)
    x = 1
    for i in range(k):
        x *= (n - i)
        x //= (i + 1)
        if x >= INF:
            return INF
    return x

def compute(n, nums):
    if not nums:
        return 1
    n -= sum(nums)
    if not n:
        return 1
    nums.sort(reverse=True)
    nums = nums[:70]
    if sum(nums) >= 6 and n > 10**4:
        return INF
    if n <= 10**4:
        A = nums[:]
        for _ in range(n):
            # 1 増やすと美味しいところを増やす
            i = max(range(len(nums)),
                    key=lambda i: (A[i] + 1) / (A[i] - nums[i] + 1))
            A[i] += 1
        x = 1
        for a, k in zip(A, nums):
            x *= comb(a, k)
        return x
    # n が大きくて、kは2種類
    # 基本的には、同じくらいの大きさにすればよいので
    ret = 1
    n += sum(nums)
    avg = n // len(nums)
    for p in itertools.product(range(avg - 4, avg + 5), repeat=len(nums)):
        if sum(p) != n:
            continue
        x = 1
        for a, k in zip(p, nums):
            x *= comb(a, k)
        if ret < x:
            ret = x
    return ret

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

if x >= INF:
    x = 'hel'
print(x)
0