結果

問題 No.2017 Mod7 Parade
ユーザー HIcoderHIcoder
提出日時 2023-07-16 19:12:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 115,972 KB
実行使用メモリ 12,844 KB
最終ジャッジ日時 2023-10-17 16:56:41
合計ジャッジ時間 6,373 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 200 ms
10,732 KB
testcase_04 AC 132 ms
8,356 KB
testcase_05 AC 98 ms
7,036 KB
testcase_06 AC 218 ms
11,524 KB
testcase_07 AC 27 ms
4,432 KB
testcase_08 AC 128 ms
7,828 KB
testcase_09 AC 51 ms
5,188 KB
testcase_10 AC 133 ms
8,092 KB
testcase_11 AC 184 ms
9,676 KB
testcase_12 AC 161 ms
8,884 KB
testcase_13 AC 256 ms
12,844 KB
testcase_14 AC 254 ms
12,844 KB
testcase_15 AC 257 ms
12,844 KB
testcase_16 AC 248 ms
12,844 KB
testcase_17 AC 252 ms
12,844 KB
testcase_18 AC 249 ms
12,844 KB
testcase_19 AC 52 ms
12,844 KB
testcase_20 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

ll mod_pow(ll x,ll y,ll mod){
    ll res=1;
    x%=mod;
    while(y>0){
        if(y&1){
            res*=x;
            res%=mod;
        }
        x*=x;
        x%=mod;
        y/=2;
    }
    return res;
}

int main(){

    int K;
    cin>>K;
    vector<int> D(K),L(K);
    for(int i=0;i<K;i++){
        cin>>D[i]>>L[i];
    }    

    /*
    dp[i][x]=i個めまで考えた際に mod7=xとなる通り数
    */

    vector dp(K+2,vector<ll>(7,0));

    const ll mod7=7;
    const ll inv9mod7=mod_pow(9,7-2,7);//9のmod7での逆元 4になる. 9*4=1 (mod7)

    dp[0][0]=1;
    for(int i=0;i<K;i++){
        for(int k=0;k<mod7;k++){
            //i個目を使わない
            dp[i+1][k]+=dp[i][k];
            dp[i+1][k]%=MOD;


            ll nx=mod_pow(10,L[i],mod7)*k%mod7;//10^L[i]

            ll d=(mod_pow(10,L[i],mod7)-1+mod7)%mod7;// 9999..9(9がL[i]-1個) のmod7 
            d*=inv9mod7%mod7;//これでtは 1111..1(1がL[i]-1個) のmod7 
            d%=mod7;
            ll t = d*D[i]%mod7;
            t%=mod7;

            nx+=t;
            nx%=mod7;

            dp[i+1][nx]+=dp[i][k];
            dp[i+1][nx]%=MOD;

        }
    }

    ll ans=0;

    for(int k=0;k<mod7;k++){
        ans+=k*dp[K][k]%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;



}
0