結果

問題 No.260 世界のなんとか3
ユーザー threepipes_sthreepipes_s
提出日時 2016-08-28 04:06:39
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,314 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 57,188 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-26 07:34:42
合計ジャッジ時間 4,252 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,752 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 9 ms
6,940 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int len;
string s;
int memo[10001][2][4][8];
int mod = 1000000007;

int valid(string s){
    int mod3 = 0;
    int mod8 = 0;
    bool hav3 = false;
    for(int i=0; i<len; i++){
        int c = s[i]-'0';
        mod3 = (mod3*10+c)%3;
        mod8 = (mod8*10+c)%8;
        if(c==3) hav3 = true;
    }
    return (mod3==0 || hav3) && mod8!=0 ? 1: 0;
}

int dfs(int d, int border, int thr, int egh){
    if(d==len){
        return memo[d][border][thr][egh] = thr%3==0&&egh!=0 ? 1: 0;
    }
    if(memo[d][border][thr][egh]>=0) return memo[d][border][thr][egh];
    int md = border==0?9:s[d]-'0';
    int ans = 0;
    for(int i=0; i<=md; i++){
        int nb = border&(i==md?1:0);
        int nthr;
        if(thr==3 || i==3) nthr = 3;
        else nthr = (thr*10+i)%3;
        ans = (ans+dfs(d+1, nb, nthr, (egh*10+i)%8))%mod;
    }
    return ans;
}

int calc(string str){
    s = str;
    len = str.size();
    for(int i=0; i<=len; i++){
        for(int j=0; j<2; j++){
            for(int k=0; k<4; k++){
                for(int l=0; l<8; l++) memo[i][j][k][l] = -1;
            }
        }
    }
    return dfs(0, 1, 0, 0);
}

int main(void){
    string a, b;
    cin >> a >> b;
    cout << ((calc(b)-calc(a)+valid(a)+mod)%mod) << endl;
    return 0;
}
0