結果

問題 No.260 世界のなんとか3
ユーザー OUDONOUDON
提出日時 2016-09-23 15:41:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 167,280 KB
実行使用メモリ 11,188 KB
最終ジャッジ日時 2023-08-11 05:27:08
合計ジャッジ時間 4,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,876 KB
testcase_01 AC 6 ms
10,964 KB
testcase_02 AC 6 ms
10,860 KB
testcase_03 WA -
testcase_04 AC 96 ms
10,948 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 68 ms
10,888 KB
testcase_12 WA -
testcase_13 AC 17 ms
11,140 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 51 ms
11,052 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 6 ms
10,968 KB
testcase_28 WA -
testcase_29 AC 96 ms
10,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MOD = 1e9 + 7;
ll dp[10001][2][2][3][8];
// dp[i桁目まで][i-1桁目まで一致しているか][3があるか][mod3][mod8]

int calc(string N)
{
    int L = N.size();
    memset(dp, 0, sizeof(dp));
    dp[0][1][0][0][0] = 1;
    rep(i, L) rep(same, 2) rep(exist, 2) rep(mod3, 3) rep(mod8, 8) {
        if (!dp[i][same][exist][mod3][mod8]) continue;

        rep(d, 10) {
            int nsame = 0;
            if (same && d > N[i] - '0') break;
            if (same && d == N[i] - '0') nsame = 1;
            
            dp[i+1][nsame][exist || d == 3][(mod3 * 10 + d) % 3][(mod8 * 10 + d) % 8] += dp[i][same][exist][mod3][mod8];
            dp[i+1][nsame][exist || d == 3][(mod3 * 10 + d) % 3][(mod8 * 10 + d) % 8] %= MOD;
        }
    }

    ll res = 0;
    rep(same, 2) rep(exist, 2) rep(mod3, 3) rep(mod8, 8) {
        if ((exist || !mod3) && mod8) res += dp[L][same][exist][mod3][mod8];
    }
    return res - 1;
}


int main()
{
    string A, B;
    cin >> A >> B;

    // A--
    for (int i=A.size() - 1; i>=0; i--) {
        if (A[i] == '0') {
            A[i] = '9';
        } else {
            A[i]--;
            break;
        }
    }

    cout << (calc(B) - calc(A) + MOD) % MOD << endl;
}

0