結果

問題 No.2017 Mod7 Parade
ユーザー srjywrdnprkt
提出日時 2023-05-13 07:11:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,243 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 109,336 KB
最終ジャッジ日時 2025-02-12 23:52:11
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

using ll = long long;
const ll modc = 1e9+7;
ll inv9;

long long mod_exp(long long b, long long e, long long m){
    if (e > 0 && b == 0) return 0;
    long long ans = 1;
    b %= m;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * b) % m;
        e = e >> 1LL;
        b = (b*b) % m;
    }

    return ans;
}

long long rep(long long b, long long e, long long m){
    return (((mod_exp(10, e, m) + m - 1) * inv9) % m * b) % m;
}

int main(){

    ll K, ans=0, r, D, L;
    inv9=mod_exp(9, 5, 7);
    cin >> K;

    vector<vector<ll>> dp(K+1, vector<ll>(7));
    dp[0][0] = 1;

    for (int i=1; i<=K; i++){
        cin >> D >> L;
        for (int j=0; j<7; j++){
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= modc;
            r = (mod_exp(10, L, 7) * j) % 7;
            r = (r + rep(D, L, 7)) % 7;
            dp[i][r] += dp[i-1][j];
            dp[i][r] %= modc;
        }
    }

    for (int i=0; i<7; i++){
        ans += (dp[K][i] * i) % modc;
        ans %= modc;
    }

    cout << ans << endl;

    return 0;
}
0