結果
問題 | No.52 よくある文字列の問題 |
ユーザー |
![]() |
提出日時 | 2023-02-12 16:57:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 158 ms / 5,000 ms |
コード長 | 8,495 bytes |
コンパイル時間 | 289 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 89,560 KB |
最終ジャッジ日時 | 2024-07-16 05:53:41 |
合計ジャッジ時間 | 2,847 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
# ライブラリインポート -------------------------------------------------------------------import mathimport collections#import statisticsimport sysfrom copy import deepcopyfrom collections import defaultdict,deque,Counterfrom sys import exitfrom heapq import heapify,heappush,heappopfrom bisect import bisect_left,bisect_right,insortfrom itertools import product,permutations,combinations,accumulate,combinations_with_replacementfrom decimal import Decimalfrom functools import lru_cachefrom typing import Generic, Iterable, Iterator, TypeVar, Union, Listfrom string import ascii_uppercase, ascii_lowercasefrom random import randint# お決まり,入力 --------------------------------------------------------------------------INF=10**18 # まれに足りない場合もあるMOD=10**9+7mod=998244353def YesNo(b): print("Yes") if b else print("No")def YESNO(b): print("YES") if b else print("NO")dxy4=[(1,0),(-1,0),(0,1),(0,-1)]dxy8=[(1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]ALPHA=ascii_uppercasealpha=ascii_lowercasesys.setrecursionlimit(2*10**6)#@lru_cache(maxsize=2*10**6)def PrintHW(array,hight,width):for i in range(hight): print(*array[i][:width])def sortx(array,num): return sorted(array, key=lambda x:x[num])def sortxr(array,num): return sorted(array, key=lambda x:x[num], reverse=True)def LL(h,w,e=0): return [[e for i in range(w)] for j in range(h)]def LLL(a,b,c,e=0): return [LL(b,c,e) for _ in range(a)]def LLLL(a,b,c,d,e=0): return [LLL(b,c,d,e) for _ in range(a)]def DD(): return defaultdict(int) # 初期値指定ならdefaultdict(lambda: 1)などとするdef LB(n): return [[] for _ in range(n)]def Dc(x): return Decimal(str(x))def II(): return int(input())def MI(): return map(int, input().split())def TI(): return tuple(map(int, input().split()))def LI(): return list(MI())def li(): return list(input())def SLI(): return sorted(LI())def MS(): return map(str, input().split())def LS(): return list(MS())def LLI(n): return [LI() for _ in range(n)]def LLS(n): return [li() for _ in range(n)]def Graph(vertex,edge):ret=LB(vertex)for i in range(edge):u,v=MI()u-=1; v-=1 # 消す場合もありret[u].append(v); ret[v].append(u)return retdef Banhei(hight,width,LLS,wall='#'): # 01マップなら0ret=[[wall]*(width+2)]for i in range(hight):ret.append([wall]+LLS[i]+[wall])ret.append([wall]*(width+2))return retdef MLI(n): # [A,B] = MLI(N)のように使うarr=LLI(n); l=len(arr[0])ret=[[] for _ in range(l)]for i in range(n):for j in range(l): ret[j].append(arr[i][j])return retdef ALLI(): # 何個与えられるかわからないときres=[]while True:try: res.append(LI())except: breakreturn res# 頻出ツール ----------------------------------------------------------------------------def acc(A):# 配列Aの累積和、最初に0を追加する。return [0] + list(accumulate(A))def acc2d(A,H,W):# サイズH*Wの2次元配列Aの2次元累積和。先頭に0を挿入。B=LL(H+1,W+1)for x in range(H):for y in range(W):B[x+1][y+1]=A[x][y]for x in range(H+1):for y in range(1,W+1):B[x][y] += B[x][y-1]for x in range(1,H+1):for y in range(W+1):B[x][y] += B[x-1][y]return Bdef fac(n, m=0):# nの階乗 | m:mod(デフォなし)if(n<=0): return 0P = 1for i in range(1,n+1):P *= iif(m>0): P %= mreturn Pdef nCmMOD(A,B,Mod):# a conb b を Mod で割った余り 1絡みの挙動に注意する。# 大量にほしいときは階乗逆元を使うやつを持ってくる。num,den=1,1for i in range(B):num*=(A-i)den*=(i+1)num%=Modden%=Modreturn (num*pow(den,Mod-2,Mod))%Moddef comb_table(N):# nCkのテーブルを作る, nCk = C[n][k]C = [[0 for i in range(N+1)] for j in range(N+1)]C[0][0] = 1for n in range(1,N+1):for k in range(n+1):C[n][k] = C[n-1][k-1] + C[n-1][k]return Cdef nHk(A,B,Mod):# 重複組合せ:1~nの中から重複を許してk個のものを選ぶ組合せreturn nCmMOD(A-1+B,A-1,Mod)def factorization(n):# 素因数分解、1に注意arr = []; temp = nfor i in range(2, int(-(-n**0.5//1))+1):if temp%i==0:cnt=0while temp%i==0:cnt+=1temp //= iarr.append([i, cnt])if temp!=1: arr.append([temp, 1])if arr==[]: arr.append([n, 1])return arrdef get_primes(n: int) -> list:# n以下の素数表sieve=[1]*nfor i in range(3,int(n**0.5)+1,2):if sieve[i]:sieve[i*i::2*i] = [0] * ((n-i*i-1)//(2*i)+1)return [2] + [i for i in range(3,n,2) if sieve[i]]#@lru_cache(maxsize=2*10**5)def division(a, b, m):# a÷bをmod mで求める 大量に使うときはメモ化return (a * pow(b, m - 2, m)) % mmemod=defaultdict(lambda:-1)def gcd(a,b):# 最大公約数while b!=0: a,b = b,a%breturn adef lcm(a,b):# 最小公倍数return(a*b // gcd(a,b))def make_divisors(n):# nの約数列挙divisors = []for i in range(1, int(n**0.5)+1):if n % i == 0:divisors.append(i)if i != n // i:divisors.append(n//i)#divisors.sort()return(divisors)def ran(A):# ランレングス圧縮L = list(A); T = []for i in range(len(L)):if i==0: T.append([L[0],1])else:if L[i]==L[i-1]: T[-1][1]+=1else: T.append([L[i],1])#return Tans1,ans2=[],[]for i in range(len(T)):ans1.append(T[i][0]) #種目ans2.append(T[i][1]) #個数return ans1,ans2def dot(P,Q,a,b,c):# P(a,b), Q(b,c) の行列積, abcに1が入るときは注意ret = LL(a,c)for i in range(a):for j in range(c):for k in range(b):ret[i][j] += P[i][k] * Q[k][j]return retdef Trans(arr,h,w):# 配列の転置ret=LL(w,h)for i in range(h):for j in range(w): ret[j][i] = arr[i][j]return retdef Rotate(x):# 2次元の地図を90度回転するreturn list(zip(*x[::-1]))# Union-Find ---------------------------------------------------------------------------#Root=list(range(N))#Size=[1]*Ndef find_root(root,x):y = root[x]if x == y: return xz = find_root(root,y)root[x] = zreturn zdef merge(root,size,x,y):x = find_root(root,x)y = find_root(root,y)if x == y: returnsx,sy = size[x],size[y]if sx < sy:sx,sy = sy,sxx,y = y,xroot[y] = xsize[x] += sydef getValue(root,size,x):return size[find_root(root,x)]def same(root,x,y):return (find_root(root,x)==find_root(root,y))# カンペ --------------------------------------------------------------------------------"""# 文字列操作print(''.join(['a', 'b', 'c'])) # abcprint("{:b}".format(b)) # 1100101010 2進数表記print("{:o}".format(b)) # 1452 8進数表記print("{:x}".format(b)) # 32a 16進数小文字表記print("{:X}".format(b)) # 32A 16進数大文字表記print("python".ljust(15,'-')) # 左詰め python---------print("python".center(15,'-'))# 中寄せ -----python----print("python".rjust(15,'-')) # 右詰め ---------pythonprint(str(29).rjust(10,'0')) # 10桁ゼロ埋め 0000000029print("{:.8f}".format(a/b)) # 小数点以下の桁数指定表示N='aiueokakikukeko'N=N.translate(str.maketrans({'a':'A'})) #N = AiueokAkikukeko# itertoolsPMT = permutations([1,2,3]) #順列 #123,132,213,231,312,321PMT2 = permutations([1,2,3],2) #長さ制限した順列 #12,13,21,23,31,32CMB1 = combinations([1,2,3],2) #組合せ #12,13,23CMB2 = combinations_with_replacement([1,2,3],2) #重複組合せ #11,12,13,22,23,33def all_comb(array):#全組合せ(個数1~N) #-,1,2,3,12,13,23,123ret=[]for i in range(len(array)+1):ret+=list(combinations(array,i))return retPRD1 = product([0,1],repeat=3) #直積 #000,001,010,011,100,101,110,111"""S=input()ans=set([])def dfs(s, x):# 素材元がs,いまできてるのがxif s=="":ans.add(x)returndfs(s[1:], x+s[0])dfs(s[:-1], x+s[-1])returndfs(S,"")print(len(ans))