結果

問題 No.315 世界のなんとか3.5
ユーザー mamekinmamekin
提出日時 2015-12-20 13:22:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,045 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 97,596 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:13:23
合計ジャッジ時間 8,621 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,348 KB
testcase_01 AC 36 ms
4,348 KB
testcase_02 AC 46 ms
4,348 KB
testcase_03 AC 58 ms
4,348 KB
testcase_04 AC 63 ms
4,348 KB
testcase_05 AC 49 ms
4,348 KB
testcase_06 AC 55 ms
4,348 KB
testcase_07 AC 50 ms
4,348 KB
testcase_08 AC 51 ms
4,348 KB
testcase_09 AC 49 ms
4,348 KB
testcase_10 AC 43 ms
4,348 KB
testcase_11 AC 56 ms
4,348 KB
testcase_12 AC 110 ms
4,348 KB
testcase_13 AC 97 ms
4,348 KB
testcase_14 AC 165 ms
4,348 KB
testcase_15 AC 165 ms
4,348 KB
testcase_16 AC 156 ms
4,348 KB
testcase_17 AC 155 ms
4,348 KB
testcase_18 AC 110 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 163 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 158 ms
4,348 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 157 ms
4,348 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 247 ms
4,348 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 272 ms
4,348 KB
testcase_35 AC 327 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000007;

int solve(const string& s, int p)
{
    int n = s.size();

    vector<vector<int> > dp(4, vector<int>(3, 0));
    dp[0][0] = 1;
    for(int i=0; i<n-5; ++i){
        vector<vector<int> > nextDp(4, vector<int>(3, 0));
        for(int a=0; a<4; ++a){
            for(int b=0; b<3; ++b){
                for(int x=0; x<=9; ++x){
                    if(!(a & 2) && x > s[i] - '0')
                        continue;

                    int a2 = a;
                    if(x == 3)
                        a2 |= 1;
                    if(x < s[i] - '0')
                        a2 |= 2;
                    int b2 = (b + x) % 3;

                    nextDp[a2][b2] += dp[a][b];
                    nextDp[a2][b2] %= MOD;
                }
            }
        }
        dp.swap(nextDp);
    }

    int y = stoi(s.substr(max(0, n - 5)));
    int ans = 0;
    for(int a=0; a<4; ++a){
        for(int b=0; b<3; ++b){
            for(int x=0; x<100000; ++x){
                if(!(a & 2) && x > y)
                    continue;

                bool isUse3 = a & 1;
                if(to_string(x).find('3') != string::npos)
                    isUse3 = true;
                int b2 = (b + x) % 3;

                if((isUse3 || b2 == 0) && x % p != 0){
                    ans += dp[a][b];
                    ans %= MOD;
                }
            }
        }
    }
    return ans;
}

int main()
{
    string a, b;
    int p;
    cin >> a >> b >> p;

    int i = a.size() - 1;
    while(a[i] == '0'){
        a[i] = '9';
        -- i;
    }
    -- a[i];

    int ans = solve(b, p) - solve(a, p);
    cout << ans << endl;

    return 0;
}
0