結果

問題 No.2703 FizzBuzz Letter Counting
ユーザー ゼットゼット
提出日時 2024-03-30 00:27:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,947 ms / 3,000 ms
コード長 3,528 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 82,288 KB
最終ジャッジ日時 2024-03-30 00:28:31
合計ジャッジ時間 61,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 42 ms
55,592 KB
testcase_02 AC 48 ms
61,908 KB
testcase_03 AC 2,469 ms
81,768 KB
testcase_04 AC 478 ms
77,348 KB
testcase_05 AC 465 ms
78,000 KB
testcase_06 AC 1,183 ms
79,336 KB
testcase_07 AC 1,938 ms
80,744 KB
testcase_08 AC 263 ms
77,180 KB
testcase_09 AC 2,223 ms
80,872 KB
testcase_10 AC 1,227 ms
79,592 KB
testcase_11 AC 244 ms
77,172 KB
testcase_12 AC 1,594 ms
80,104 KB
testcase_13 AC 670 ms
78,364 KB
testcase_14 AC 2,589 ms
81,772 KB
testcase_15 AC 2,500 ms
81,388 KB
testcase_16 AC 2,464 ms
81,776 KB
testcase_17 AC 398 ms
77,328 KB
testcase_18 AC 1,835 ms
80,488 KB
testcase_19 AC 1,477 ms
79,592 KB
testcase_20 AC 1,748 ms
80,360 KB
testcase_21 AC 1,143 ms
79,464 KB
testcase_22 AC 679 ms
77,956 KB
testcase_23 AC 2,692 ms
81,772 KB
testcase_24 AC 1,394 ms
79,592 KB
testcase_25 AC 1,522 ms
80,488 KB
testcase_26 AC 2,588 ms
81,772 KB
testcase_27 AC 2,230 ms
80,872 KB
testcase_28 AC 2,833 ms
81,768 KB
testcase_29 AC 2,904 ms
81,768 KB
testcase_30 AC 2,838 ms
82,284 KB
testcase_31 AC 2,760 ms
81,772 KB
testcase_32 AC 2,815 ms
81,772 KB
testcase_33 AC 2,837 ms
82,288 KB
testcase_34 AC 2,926 ms
81,776 KB
testcase_35 AC 2,906 ms
81,776 KB
testcase_36 AC 2,947 ms
81,768 KB
testcase_37 AC 2,885 ms
81,768 KB
testcase_38 AC 2,911 ms
82,160 KB
testcase_39 AC 2,890 ms
82,160 KB
testcase_40 AC 2,891 ms
82,160 KB
testcase_41 AC 2,916 ms
82,156 KB
testcase_42 AC 2,824 ms
81,772 KB
testcase_43 AC 42 ms
55,592 KB
testcase_44 AC 40 ms
53,460 KB
testcase_45 AC 44 ms
55,592 KB
testcase_46 AC 42 ms
55,592 KB
testcase_47 AC 42 ms
55,592 KB
testcase_48 AC 40 ms
53,460 KB
testcase_49 AC 42 ms
55,592 KB
testcase_50 AC 42 ms
55,592 KB
testcase_51 AC 42 ms
55,592 KB
testcase_52 AC 41 ms
55,592 KB
testcase_53 AC 41 ms
55,592 KB
testcase_54 AC 39 ms
53,460 KB
testcase_55 AC 46 ms
53,460 KB
testcase_56 AC 41 ms
55,592 KB
testcase_57 AC 41 ms
55,592 KB
testcase_58 AC 40 ms
53,460 KB
testcase_59 AC 40 ms
53,460 KB
testcase_60 AC 39 ms
53,460 KB
testcase_61 AC 40 ms
53,460 KB
testcase_62 AC 39 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
u15=[0]*60
v15=[0]*60
v15[0]=10
mod=998244353
for j in range(1,60):
  x,y=(u15[j-1]**2%mod)*15+2*v15[j-1]*u15[j-1],v15[j-1]**2
  if y>=15:
    x+=y//15
    y%=15
  x%=mod
  y%=mod
  u15[j],v15[j]=x,y
u5=[0]*60
v5=[0]*60
u5[0]=2
gg=[1]*60
for j in range(1,60):
  gg[j]=gg[j-1]*2
for j in range(1,60):
  x,y=(u5[j-1]**2%mod)*5+2*v5[j-1]*u5[j-1],v5[j-1]**2
  if y>=5:
    x+=y//5
    y%=5
  x%=mod
  y%=mod
  u5[j],v5[j]=x,y
u0=[0]*60
v0=[0]*60
v0[0]=10
for j in range(1,60):
  v0[j]=v0[j-1]**2
  v0[j]%=mod
u3=[0]*60
v3=[0]*60
u3[0]=3
v3[0]=1
for j in range(1,60):
  x,y=(u3[j-1]**2%mod)*3+2*v3[j-1]*u3[j-1],v3[j-1]**2
  if y>=3:
    x+=y//3
    y%=3
  x%=mod
  y%=mod
  u3[j],v3[j]=x,y
o=0
def g(l,c):
  x,y=0,1
  if c==15:
    for k in range(60):
      if gg[k]>l:
        break
      if (l>>k)&1:
        a,b=u15[k],v15[k]
        x2,y2=(x*a%mod)*15+y*a+b*x,b*y
        x2%=mod
        y2%=mod
        if y2>=15:
          x2+=y2//15
          y2%=15
        x,y=x2,y2
  elif c==5:
    for k in range(60):
      if gg[k]>l:
        break
      if (l>>k)&1:
        a,b=u5[k],v5[k]
        x2,y2=(x*a%mod)*5+y*a+b*x,b*y
        x2%=mod
        y2%=mod
        if y2>=5:
          x2+=y//5
          y2%=5
        x,y=x2,y2
  elif c==3:
    for k in range(60):
      if gg[k]>l:
        break
      if (l>>k)&1:
        a,b=u3[k],v3[k]
        x2,y2=(x*a%mod)*3+y*a+b*x,b*y
        x2%=mod
        y2%=mod
        if y2>=3:
          x2+=y//3
          y2%=3
        x,y=x2,y2
  else:
    for k in range(60):
      if gg[k]>l:
        break
      if (l>>k)&1:
        y*=v0[k]
        y%=mod
  return x,y
mm=0
def f(a2,l,c):
  global mm
  x,y=0,0
  a,b=0,0
  for k in range(60,-1,-1):
    mm+=1
    x,y=((x*a)%mod)*c+(b+1)*x+y*a,y*(b+1)
    x+=y//c
    y%=c
    a,b=((a**2)%mod)*c+b*a+a*b,b*b
    a+=b//c
    b%=c
    x%=mod
    a%=mod
    if (l>>k)&1:
      x*=10
      y*=10
      x%=mod
      y+=a2
      x+=y//c
      y%=c
      if a==0 and b==0:
        b=10
        continue
      a*=10
      b*=10
      a%=mod
      a+=b//c
      b%=c
      x%=mod
      a%=mod
  return x,y
def h(n):
  if n==0:
    return 0
  ans=1-(n+1)*pow(10,n,mod)+n*pow(10,n+1,mod)
  ans%=mod
  ans*=pow(81,-1,mod)
  ans%=mod
  ans*=480
  ans%=mod
  w=10*(pow(10,n,mod)-1)
  w%=mod
  w*=pow(9,-1,mod)
  w%=mod
  w*=96
  result=ans+w
  result%=mod
  return result
count=0
ans=''
L=[]
for i in range(N):
  v,l=map(int,input().split())
  if count+l<=2:
    ans+=str(v)*l
  count+=l
  L.append((v,l))
def t(a,l,count,c):
  x1,y1=f(a,l,c)
  x2,y2=g(count,c)
  x,y=((x1*x2)%mod)*c+y1*x2+x1*y2,y1*y2
  if y>=c:
    x+=y//c
    y%=c
  return x,y
if count<=2:
  result=0
  x=int(ans)
  for y in range(1,x+1):
    if y%15==0:
      result+=8
    elif y%5==0:
      result+=4
    elif y%3==0:
      result+=4
    else:
      z=str(y)
      result+=len(z)
  print(result)
  exit()
a0,a1=0,0
b0,b1=0,0
c0,c1=0,0
d=0
count=0
for i in range(N-1,-1,-1):
  v,l=L[i][:]
  a2,a3=t(v,l,count,15)
  a0+=a2
  a1+=a3
  a0+=a1//15
  a1%=15
  b2,b3=t(v,l,count,5)
  b0+=b2
  b1+=b3
  b0+=b1//5
  b1%=5
  c2,c3=t(v,l,count,3)
  c0+=c2
  c1+=c3
  c0+=c1//3
  c1%=3
  d2,d3=t(v,l,count,mod)
  d+=d3
  d%=mod
  count+=l
u=10**9+7
result=a0*8+(b0-a0)*4+(c0-a0)*4
result%=mod
d-=a0+(b0-a0)+(c0-a0)
_,k=f(9,count-1,mod)
k1,_=f(9,count-1,15)
k2,_=f(9,count-1,5)
k3,_=f(9,count-1,3)
w=k-(k1+(k2-k1)+(k3-k1))
d-=w
result+=d*count
result+=h(count-3)
result%=mod
for x in range(1,100):
  if x%5!=0 and x%3!=0:
    y=str(x)
    result+=len(y)
    result%=mod
print(result)
0