結果

問題 No.260 世界のなんとか3
ユーザー uenokuuenoku
提出日時 2017-01-31 02:21:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 82,860 KB
実行使用メモリ 11,092 KB
最終ジャッジ日時 2023-08-25 13:47:02
合計ジャッジ時間 5,844 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,936 KB
testcase_01 AC 4 ms
10,940 KB
testcase_02 AC 4 ms
11,048 KB
testcase_03 AC 268 ms
10,904 KB
testcase_04 AC 268 ms
10,940 KB
testcase_05 AC 54 ms
11,092 KB
testcase_06 AC 38 ms
10,876 KB
testcase_07 AC 181 ms
10,904 KB
testcase_08 AC 129 ms
10,980 KB
testcase_09 AC 75 ms
10,916 KB
testcase_10 AC 206 ms
10,948 KB
testcase_11 AC 191 ms
10,960 KB
testcase_12 AC 118 ms
10,924 KB
testcase_13 AC 36 ms
11,012 KB
testcase_14 AC 172 ms
10,960 KB
testcase_15 AC 49 ms
10,876 KB
testcase_16 AC 150 ms
10,944 KB
testcase_17 AC 119 ms
10,892 KB
testcase_18 AC 116 ms
10,884 KB
testcase_19 AC 150 ms
10,932 KB
testcase_20 AC 107 ms
10,884 KB
testcase_21 AC 93 ms
10,916 KB
testcase_22 AC 173 ms
10,888 KB
testcase_23 AC 19 ms
10,924 KB
testcase_24 AC 134 ms
10,892 KB
testcase_25 AC 173 ms
10,984 KB
testcase_26 AC 99 ms
10,976 KB
testcase_27 AC 3 ms
11,024 KB
testcase_28 AC 189 ms
10,988 KB
testcase_29 AC 338 ms
11,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
lli f(string s)
{
    int n = s.size();
    lli dp[10040][2][3][2][8] = {};  //pos,less,mod,has3,mod8
    dp[0][0][0][0][0] = 1;
    rep(i, n) rep(j, 2) rep(k, 3) rep(l, 2) rep(q, 8)
    {
        int lim = j ? 9 : s[i] - '0';
        rep(m, lim + 1)
        {
            dp[i + 1][j || m < lim][(k + m) % 3][l || m == 3][(10 * q + m) % 8] += dp[i][j][k][l][q];
            dp[i + 1][j || m < lim][(k + m) % 3][l || m == 3][(10 * q + m) % 8] %= MOD;
        }
    }
    lli a = 0;
    rep(j, 2)
    {
        rep(l, 2)
        {
            rep(k, 3)
            {
                rep(q, 8)
                {
                    if ((l || k == 0) && q != 0) {
                        a += dp[n][j][k][l][q];
                        a %= MOD;
                    }
                }
            }
        }
    }
    return a;
}
int main()
{
    string s, t;
    cin >> s;
    lli A = f(s);
    cin >> t;
    lli B = f(t);
    int sum = 0;
    bool flag = false;
    rep(i, s.size())
    {
        sum += s[i] - '0';
        if (s[i] == '3') {
            flag = true;
        }
    }
    if (sum % 3 == 0) {
        flag = true;
    }
    bool ok = false;
    if (s.size() >= 3) {
        int k = s.size();
        int j = 100 * (s[k - 3] - '0');
        j += 10 * (s[k - 2] - '0');
        j += (s[k - 1] - '0');
        if (j % 8 != 0) {
            ok = true;
        }
    } else {
        int k = s.size();
        int j = 10 * (s[k - 2] - '0');
        j += (s[k - 1] - '0');
        if (k % 8 != 0)
            ok = true;
    }
    if (flag && ok) {
        A--;
    }
    cout << (B - A + MOD) % MOD << endl;
}
0