結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,732 KB
testcase_01 AC 19 ms
8,756 KB
testcase_02 AC 20 ms
8,900 KB
testcase_03 AC 20 ms
8,820 KB
testcase_04 AC 20 ms
8,720 KB
testcase_05 WA -
testcase_06 AC 19 ms
8,732 KB
testcase_07 AC 20 ms
8,736 KB
testcase_08 AC 20 ms
8,772 KB
testcase_09 AC 20 ms
8,776 KB
testcase_10 AC 20 ms
8,728 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 20 ms
8,724 KB
testcase_14 AC 20 ms
8,896 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 20 ms
8,920 KB
testcase_20 AC 20 ms
8,856 KB
testcase_21 AC 20 ms
8,860 KB
testcase_22 AC 19 ms
8,908 KB
testcase_23 AC 20 ms
8,732 KB
testcase_24 WA -
testcase_25 AC 32 ms
8,768 KB
testcase_26 AC 35 ms
8,956 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 19 ms
8,928 KB
testcase_31 AC 18 ms
8,980 KB
testcase_32 AC 288 ms
27,480 KB
testcase_33 AC 280 ms
26,420 KB
testcase_34 AC 283 ms
27,484 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 23 ms
8,872 KB
testcase_51 RE -
testcase_52 RE -
testcase_53 AC 301 ms
19,388 KB
testcase_54 AC 303 ms
19,532 KB
testcase_55 AC 315 ms
19,512 KB
testcase_56 AC 318 ms
19,576 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
    avg = n // len(nums)
    for p in itertools.product(range(avg - 4, avg + 5), repeat=len(nums)):
        if sum(avg) != 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