結果

問題 No.260 世界のなんとか3
ユーザー Grun1396Grun1396
提出日時 2018-06-01 20:50:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,593 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 55,160 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2023-09-12 21:26:22
合計ジャッジ時間 4,208 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
41,304 KB
testcase_01 AC 21 ms
41,268 KB
testcase_02 AC 21 ms
41,212 KB
testcase_03 WA -
testcase_04 AC 159 ms
41,316 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 56 ms
41,240 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 79 ms
41,392 KB
testcase_13 WA -
testcase_14 AC 109 ms
41,260 KB
testcase_15 AC 43 ms
41,368 KB
testcase_16 AC 98 ms
41,308 KB
testcase_17 WA -
testcase_18 AC 79 ms
41,324 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 89 ms
41,296 KB
testcase_25 AC 109 ms
41,300 KB
testcase_26 AC 69 ms
41,376 KB
testcase_27 AC 20 ms
41,364 KB
testcase_28 AC 118 ms
41,404 KB
testcase_29 AC 197 ms
41,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
typedef long long ll;

const int MOD = 1e9+7;
int dp[101010][2][2][3][8];

string A,B;

int func(string A,bool less){
    int n = A.length();
    rep(i,101010){
        rep(j,2){
            rep(k,2){
                rep(l,3){
                    rep(m,8){
                        dp[i][j][k][l][m] = 0;
                    }
                }
            }
        }
    }

    dp[0][0][0][0][0] = 1;
    
    rep(i,n){
        rep(j,2){
            rep(k,2){
                rep(l,3){
                    rep(m,8){
                        int lim = j ? 9 : A[i] - '0';
                        rep(d,lim+1){
                            ( dp[i+1]
                                [j || d < lim]
                                [k || d == 3]
                                [(l+d)%3]
                                [(m*10+d)%8]
                                += dp[i][j][k][l][m]) %= MOD;
                        }
                    }
                }
            }
        }
    }

    int ans = 0;
    int index = 0;
    if(!less) index = 1;
    reps(j,index,2){
        rep(k,2){
            rep(l,3){
                rep(m,8){
                    if( (k || l == 0) && m != 0){
                        (ans += dp[n][j][k][l][m]) %= MOD;
                    }
                }
            }
        }
    }

    return ans;
}

int main(){
    cin >> A >> B;
    int ans = func(B,true)-func(A,false);
    cout << ans << endl;

    return 0;
}
0