結果

問題 No.260 世界のなんとか3
ユーザー threepipes_sthreepipes_s
提出日時 2016-08-28 05:42:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 58,076 KB
実行使用メモリ 7,128 KB
最終ジャッジ日時 2024-04-26 10:03:21
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 82 ms
7,040 KB
testcase_04 AC 79 ms
7,108 KB
testcase_05 AC 17 ms
6,940 KB
testcase_06 AC 11 ms
6,944 KB
testcase_07 AC 55 ms
6,940 KB
testcase_08 AC 39 ms
6,940 KB
testcase_09 AC 22 ms
6,944 KB
testcase_10 AC 59 ms
6,944 KB
testcase_11 AC 53 ms
6,944 KB
testcase_12 AC 35 ms
6,940 KB
testcase_13 AC 11 ms
6,940 KB
testcase_14 AC 51 ms
6,940 KB
testcase_15 AC 15 ms
6,944 KB
testcase_16 AC 44 ms
6,944 KB
testcase_17 AC 35 ms
6,944 KB
testcase_18 AC 35 ms
6,940 KB
testcase_19 AC 44 ms
6,940 KB
testcase_20 AC 31 ms
6,944 KB
testcase_21 AC 28 ms
6,940 KB
testcase_22 AC 51 ms
6,940 KB
testcase_23 AC 7 ms
6,940 KB
testcase_24 AC 40 ms
6,944 KB
testcase_25 AC 42 ms
6,948 KB
testcase_26 AC 41 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 76 ms
7,128 KB
testcase_29 AC 76 ms
7,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

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

bool out(int a, int l, int r){
    return a<l || r<=a;
}

int valid(string s){
    int mod3 = 0;
    int mod8 = 0;
    bool hav3 = false;
    for(int i=0; i<s.size(); 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 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 memo[d][border][thr][egh] = 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