結果

問題 No.2017 Mod7 Parade
ユーザー umimelumimel
提出日時 2022-07-22 22:58:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 168,880 KB
実行使用メモリ 4,652 KB
最終ジャッジ日時 2023-09-17 11:38:31
合計ジャッジ時間 4,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 143 ms
4,428 KB
testcase_04 AC 96 ms
4,380 KB
testcase_05 AC 71 ms
4,380 KB
testcase_06 AC 158 ms
4,568 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 90 ms
4,380 KB
testcase_09 AC 35 ms
4,380 KB
testcase_10 AC 91 ms
4,376 KB
testcase_11 AC 125 ms
4,380 KB
testcase_12 AC 110 ms
4,380 KB
testcase_13 AC 181 ms
4,596 KB
testcase_14 AC 182 ms
4,616 KB
testcase_15 AC 182 ms
4,628 KB
testcase_16 AC 182 ms
4,652 KB
testcase_17 AC 182 ms
4,548 KB
testcase_18 AC 176 ms
4,640 KB
testcase_19 AC 39 ms
4,536 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

ll pow_mod(ll x, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*x)%mod;
        x = x*x%mod;
        n >>=1;
    }
    return ret;
}

int main(){
    ll k;
    cin >> k;

    vector<ll> d(k), l(k);
    rep(i, k) cin >> d[i] >> l[i];

    vector<ll> dp(7, 0);
    dp[0] = 1;
    ll inv9 = pow_mod(9, 5, 7);
    for(ll i=0; i<=k-1; i++){
        ll prefix = 0;
        prefix = d[i]%7;
        prefix *= (pow_mod(10, l[i], 7)+6)%7;
        prefix %= 7;
        prefix *= inv9;
        prefix %= 7;

        vector<ll> dp2(7, 0);
        rep(j, 7) dp2[j] = dp[j];

        rep(j, 7){
            ll tmp = (j * pow_mod(10, l[i], 7))%7;
            tmp += prefix;
            tmp %= 7;
            dp2[tmp] += dp[j];
            dp2[tmp] %= MOD;
        }

        rep(j, 7) dp[j] = dp2[j];
    }

    ll ans = 0;
    rep(i, 7){
        ans += (i*dp[i])%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}
0