Submission #71156128


Source Code Expand

mod = 998244353

S = list(map(int, input().strip()))
n = len(S)

fact = [1] * (n + 1)
for i in range(1, n + 1):
  fact[i] = fact[i - 1] * i % mod

invfact = [1] * (n + 1)
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n, 0, -1):
  invfact[i - 1] = invfact[i] * i % mod

def comb(a, b):
  if b < 0 or b > a:
    return 0
  return fact[a] * invfact[b] % mod * invfact[a - b] % mod

right = [0] * 10
for s in S:
  right[s] += 1

ans = 0
left = [0] * 10
for s in S:
  right[s] -= 1
  if s != 9:
    L = left[s]
    R = right[s + 1]
    if R > 0:
      ans += comb(L + R, R - 1)
      ans %= mod
  left[s] += 1
  # print(s, ans)

print(ans)

Submission Info

Submission Time
Task F - 1122 Subsequence 2
User uparupaaa
Language Python (PyPy 3.11-v7.3.20)
Score 500
Code Size 681 Byte
Status AC
Exec Time 141 ms
Memory 170080 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 50 ms 79604 KiB
00_sample_01.txt AC 52 ms 79872 KiB
00_sample_02.txt AC 51 ms 79780 KiB
01_random_00.txt AC 48 ms 79872 KiB
01_random_01.txt AC 121 ms 169768 KiB
01_random_02.txt AC 128 ms 169764 KiB
01_random_03.txt AC 135 ms 169912 KiB
01_random_04.txt AC 137 ms 170000 KiB
01_random_05.txt AC 129 ms 169916 KiB
01_random_06.txt AC 136 ms 170044 KiB
01_random_07.txt AC 133 ms 169604 KiB
01_random_08.txt AC 99 ms 153532 KiB
01_random_09.txt AC 128 ms 170080 KiB
01_random_10.txt AC 91 ms 141584 KiB
01_random_11.txt AC 133 ms 169848 KiB
01_random_12.txt AC 60 ms 92436 KiB
01_random_13.txt AC 130 ms 169916 KiB
01_random_14.txt AC 68 ms 106064 KiB
01_random_15.txt AC 141 ms 169696 KiB
01_random_16.txt AC 76 ms 117720 KiB
01_random_17.txt AC 134 ms 169580 KiB
01_random_18.txt AC 133 ms 169888 KiB
01_random_19.txt AC 131 ms 169756 KiB
01_random_20.txt AC 126 ms 169796 KiB
01_random_21.txt AC 123 ms 170004 KiB
01_random_22.txt AC 72 ms 110116 KiB
01_random_23.txt AC 73 ms 108980 KiB