結果
問題 | No.295 hel__world |
ユーザー |
![]() |
提出日時 | 2021-03-16 13:42:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,874 ms / 5,000 ms |
コード長 | 1,890 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 211,968 KB |
最終ジャッジ日時 | 2024-11-07 23:46:45 |
合計ジャッジ時間 | 11,785 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 53 |
ソースコード
import syssys.setrecursionlimit(10**6)int1 = lambda x: int(x)-1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.buffer.readline())def LI(): return list(map(int, sys.stdin.buffer.readline().split()))def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def BI(): return sys.stdin.buffer.readline().rstrip()def SI(): return sys.stdin.buffer.readline().rstrip().decode()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = 10**16# md = 998244353md = 10**9+7from heapq import *def RLE(s):cc=[]ww=[]pc=s[0]w=0for c in s:if c==pc:w+=1else:cc.append(pc)ww.append(w)w=1pc=ccc.append(pc)ww.append(w)return cc,wwlim=1<<62aa=LI()s=BI()cc,ll=RLE(s)cnt=[[] for _ in range(26)]for c,l in zip(cc,ll):cnt[c-97].append(l)# print(cnt)ans=1for i,(a,cc) in enumerate(zip(aa,cnt)):if not cc:continues=sum(cc)if a<s:print(0)exit()aa[i]=a-sfor i, (a, cc) in enumerate(zip(aa, cnt)):if not cc or a==0:continueif a>10000000 and sum(cc)>2:print("hel")exit()if sum(cc)==1:cur=a+1elif sum(cc)==2:a += 2if len(cc)==1:cur=a*(a-1)//2else:cur=(a//2)*(a-a//2)else:hp=[]cur=1for c in cc:heappush(hp,(-(c+1)/(c-c+1),c,c))cur=1for _ in range(a):m,n,r=heappop(hp)cur=cur*(n+1)//(n-r+1)heappush(hp,(-(n+2)/(n-r+2),n+1,r))ans*=curif ans>=lim:print("hel")exit()print(ans)