結果

問題 No.2017 Mod7 Parade
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-01-28 02:39:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,054 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 93,860 KB
最終ジャッジ日時 2024-01-28 02:39:25
合計ジャッジ時間 14,478 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 805 ms
89,516 KB
testcase_04 AC 584 ms
85,596 KB
testcase_05 AC 429 ms
82,652 KB
testcase_06 AC 894 ms
91,432 KB
testcase_07 AC 204 ms
76,636 KB
testcase_08 AC 548 ms
84,700 KB
testcase_09 AC 243 ms
76,764 KB
testcase_10 AC 530 ms
84,700 KB
testcase_11 AC 748 ms
88,028 KB
testcase_12 AC 660 ms
87,388 KB
testcase_13 AC 987 ms
93,484 KB
testcase_14 AC 1,018 ms
93,484 KB
testcase_15 AC 1,007 ms
93,480 KB
testcase_16 AC 1,021 ms
93,480 KB
testcase_17 AC 1,028 ms
93,480 KB
testcase_18 AC 1,054 ms
93,472 KB
testcase_19 AC 173 ms
93,860 KB
testcase_20 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2017

SMALL_MOD = 7
MOD = 10 ** 9 + 7

def main():
    K = int(input())
    dl = []
    for _ in range(K):
        D, L = map(int, input().split())
        dl.append((D, L))
    

    dp = [[0] * SMALL_MOD for _ in range(K + 1)]
    dp[0][0] = 1
    for i in range(K):
        d, l = dl[i]
        pow_10_l = pow(10, l, SMALL_MOD)

        # dをl個並べた時の値計算
        val = 0
        x = d
        length = 1
        while l > 0:
            y = pow(10, length, SMALL_MOD)
            if l % 2 == 1:
                val *= y
                val %= SMALL_MOD
                val += x
                val %= SMALL_MOD
            
            y0 = (x * y) % SMALL_MOD
            x = (y0 + x) % SMALL_MOD
            length *= 2
            l //= 2

        for j in range(SMALL_MOD):
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD

            new_j = j * pow_10_l
            new_j %= SMALL_MOD
            new_j += val
            new_j %= SMALL_MOD

            dp[i + 1][new_j] += dp[i][j]
            dp[i + 1][new_j] %= MOD

    answer = 0
    for i in range(SMALL_MOD):      
        ans = i * dp[-1][i]
        ans %= MOD
        answer += ans
        answer %= MOD
    print(answer)  




if __name__ == '__main__':
    main()
0