結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー hibit_athibit_at
提出日時 2024-02-23 22:16:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 672 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 82,820 KB
最終ジャッジ日時 2024-02-23 22:16:47
合計ジャッジ時間 9,689 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 107 ms
82,376 KB
testcase_15 WA -
testcase_16 AC 86 ms
81,436 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 75 ms
80,812 KB
testcase_24 AC 78 ms
80,812 KB
testcase_25 WA -
testcase_26 AC 76 ms
80,812 KB
testcase_27 AC 104 ms
80,812 KB
testcase_28 AC 76 ms
80,812 KB
testcase_29 WA -
testcase_30 AC 76 ms
80,812 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def naive(n):
    return n*(n+1)//2

def solve(s,mod):
    # s = str(n)
    m = len(s)
    sum = 0
    # print(m)
    dp = [0] * (m+1)
    factor = [1] * m
    for i in range(m,1,-1):
        factor[i-2] = factor[i-1]*10%mod
    # print(factor)
    for i in range(m):
        last = sum + int(s[i])*factor[i]
        last %= mod
        # print(last)
        dp[i+1] = dp[i] + (last + sum + 1)*(last-sum)//2
        dp[i+1] %= mod
        sum = last
    return dp[m]

# random

# for i in range(1,150):
#     assert(naive(i) == solve(i))

# stress

t = int(input())

for _ in range(t):
    n,m = list(map(str, input().split(' ')))
    m = int(m)
    print(solve(n,m))
    
0