結果

問題 No.315 世界のなんとか3.5
ユーザー 小指が強い人小指が強い人
提出日時 2016-08-19 13:45:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 3,609 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 153,204 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-08-07 14:21:21
合計ジャッジ時間 7,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 22 ms
6,184 KB
testcase_03 AC 3 ms
5,372 KB
testcase_04 AC 3 ms
5,412 KB
testcase_05 AC 5 ms
5,420 KB
testcase_06 AC 13 ms
4,376 KB
testcase_07 AC 4 ms
5,440 KB
testcase_08 AC 5 ms
5,500 KB
testcase_09 AC 3 ms
5,368 KB
testcase_10 AC 3 ms
5,436 KB
testcase_11 AC 3 ms
5,380 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = (a); (i) < (ll)(n); (i)++)
#define RREP(i, a, n) for(ll i = (n)-1; (i) >= (a); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007ULL
#define _SPLIT " "

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T& a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(22) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(22) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

ll tk[3][2]={0};
ll dt[100010]={0};
int p,pa;

ll md_add(ll x,ll y){return ((x%MD)+(y%MD))%MD;}

ll f(string& x,bool f){
    int n=x.size();
    int ps=to_string(pa).size()-1;
    if(n<=ps)return dt[atoi(x.c_str())-f];
    ll dp[20010][2][2][3]={0};
    dp[0][0][0][0]=1;
    rep(i,n-ps){
        int dg=x[i]-'0';
        rep(x,2)rep(y,2)rep(z,3)rep(w,y?10:dg+1){
            ll &t=dp[i+1][x||w==3][y||w<dg][(z+w)%3];
            t=(t+dp[i][x][y][z])%MD;
        }
    }
    ll res=0;
    //dp[i+1][x||w==3][y||y<dg][(z+w)%3];
    rep(w,2)REP(i,1,2)rep(j,3)rep(k,3){
        if(w==1){
            res=md_add(res,dp[n-ps][w][i][j]*tk[k][0]);
            res=md_add(res,dp[n-ps][w][i][j]*tk[k][1]);
        }
        else{
            res=md_add(res,dp[n-ps][w][i][j]*tk[k][1]);
            if((j+k)%3==0)
            res=md_add(res,dp[n-ps][w][i][j]*tk[k][0]);
        }
    }
    int nr4=0;
    bool in3=false;
    rep(i,n-ps)nr4+=x[i]-'0',in3|=(x[i]=='3');
    int nd3=atoi(x.c_str()+n-ps)-f;
    REP(i,0,nd3+1){
        if(i%p==0)continue;
        string s=to_string(i);
        bool find=in3;
        rep(i,s.size())find|=(s[i]=='3');
        if((i+nr4)%3==0||find)res=md_add(res,1);
    }
    return res;
}

int main(void)
{
    string a,b;
    read(a,b,p);
    pa=1000;
    if(p==80)pa=10000;
    else if(p==800)pa=100000;
    REP(i,1,pa){
        dt[i]+=dt[i-1];
        if(i%p==0)continue;
        string s=to_string(i);
        bool find=false;
        rep(i,s.size())find|=(s[i]=='3');
        tk[i%3][find]++;
        if(i%3==0||find)dt[i]++;
    }
    write(md_add(f(b,false),MD-f(a,true)));
    return 0;
}
0