結果

問題 No.295 hel__world
ユーザー maspymaspy
提出日時 2020-05-04 13:43:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,934 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 27,440 KB
最終ジャッジ日時 2023-09-06 13:20:10
合計ジャッジ時間 5,633 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,888 KB
testcase_01 AC 19 ms
8,700 KB
testcase_02 AC 20 ms
8,840 KB
testcase_03 AC 20 ms
8,720 KB
testcase_04 AC 20 ms
8,704 KB
testcase_05 WA -
testcase_06 AC 20 ms
8,904 KB
testcase_07 AC 20 ms
8,900 KB
testcase_08 AC 20 ms
8,720 KB
testcase_09 AC 20 ms
8,900 KB
testcase_10 AC 19 ms
8,836 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 21 ms
8,704 KB
testcase_14 AC 20 ms
8,840 KB
testcase_15 AC 20 ms
8,844 KB
testcase_16 AC 19 ms
8,772 KB
testcase_17 AC 19 ms
8,740 KB
testcase_18 AC 20 ms
8,720 KB
testcase_19 AC 20 ms
8,840 KB
testcase_20 AC 20 ms
8,848 KB
testcase_21 AC 20 ms
8,764 KB
testcase_22 AC 20 ms
8,856 KB
testcase_23 AC 20 ms
8,900 KB
testcase_24 WA -
testcase_25 AC 34 ms
8,720 KB
testcase_26 AC 37 ms
8,876 KB
testcase_27 AC 20 ms
8,700 KB
testcase_28 AC 19 ms
8,912 KB
testcase_29 AC 25 ms
8,880 KB
testcase_30 AC 20 ms
8,728 KB
testcase_31 AC 20 ms
8,736 KB
testcase_32 AC 317 ms
27,440 KB
testcase_33 AC 312 ms
27,180 KB
testcase_34 AC 313 ms
27,188 KB
testcase_35 AC 20 ms
8,772 KB
testcase_36 AC 20 ms
8,724 KB
testcase_37 WA -
testcase_38 AC 20 ms
8,780 KB
testcase_39 AC 20 ms
8,844 KB
testcase_40 AC 20 ms
8,904 KB
testcase_41 AC 20 ms
8,696 KB
testcase_42 AC 20 ms
8,748 KB
testcase_43 AC 19 ms
8,872 KB
testcase_44 AC 20 ms
8,860 KB
testcase_45 AC 19 ms
8,764 KB
testcase_46 AC 19 ms
8,808 KB
testcase_47 AC 20 ms
8,732 KB
testcase_48 AC 20 ms
8,724 KB
testcase_49 AC 20 ms
8,908 KB
testcase_50 AC 25 ms
8,860 KB
testcase_51 AC 20 ms
8,724 KB
testcase_52 AC 20 ms
8,724 KB
testcase_53 AC 331 ms
19,392 KB
testcase_54 AC 325 ms
19,356 KB
testcase_55 AC 329 ms
19,404 KB
testcase_56 AC 325 ms
19,360 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)

@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