結果

問題 No.260 世界のなんとか3
ユーザー face4face4
提出日時 2019-09-25 14:23:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,910 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 73,812 KB
実行使用メモリ 7,488 KB
最終ジャッジ日時 2023-10-22 04:02:30
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,436 KB
testcase_01 AC 3 ms
7,436 KB
testcase_02 AC 3 ms
7,436 KB
testcase_03 AC 66 ms
7,488 KB
testcase_04 AC 67 ms
7,488 KB
testcase_05 AC 15 ms
7,448 KB
testcase_06 AC 11 ms
7,448 KB
testcase_07 AC 47 ms
7,476 KB
testcase_08 AC 32 ms
7,464 KB
testcase_09 AC 19 ms
7,452 KB
testcase_10 AC 55 ms
7,472 KB
testcase_11 AC 48 ms
7,476 KB
testcase_12 AC 31 ms
7,456 KB
testcase_13 AC 12 ms
7,444 KB
testcase_14 AC 46 ms
7,476 KB
testcase_15 AC 14 ms
7,448 KB
testcase_16 AC 40 ms
7,468 KB
testcase_17 AC 32 ms
7,460 KB
testcase_18 AC 30 ms
7,464 KB
testcase_19 AC 40 ms
7,468 KB
testcase_20 AC 29 ms
7,460 KB
testcase_21 AC 26 ms
7,456 KB
testcase_22 AC 46 ms
7,468 KB
testcase_23 AC 7 ms
7,440 KB
testcase_24 AC 35 ms
7,468 KB
testcase_25 AC 45 ms
7,468 KB
testcase_26 AC 28 ms
7,468 KB
testcase_27 AC 4 ms
7,436 KB
testcase_28 AC 70 ms
7,484 KB
testcase_29 AC 83 ms
7,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod = 1000000007;

void minusone(string &s){
    reverse(s.begin(), s.end());
    int carry = 1;
    for(int i = 0; carry > 0 && i < s.length(); i++){
        carry = s[i] == '0';
        s[i] = (s[i] == '0' ? '9' : s[i]-1);
    }
    reverse(s.begin(), s.end());
    if(s.length() > 1 && s[0] == '0') s = s.substr(1);
}

// index - less - has three - modulo three - modulo eight
int dp[10001][2][2][3][8];

int f(string s){
    memset(dp, 0, sizeof(dp));
    int n = s.length();
    dp[0][0][0][0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2; k++){
                for(int l = 0; l < 3; l++){
                    for(int m = 0; m < 8; m++){
                        for(int num = 0; num <= 9; num++){
                            if(j == 0 && num > s[i]-'0')    continue;
                            int ni = i+1;
                            int nj = j | (num < s[i]-'0');
                            int nk = k | (num == 3);
                            int nl = (10*l+num)%3;
                            int nm = (10*m+num)%8;
                            dp[ni][nj][nk][nl][nm] += dp[i][j][k][l][m];
                            dp[ni][nj][nk][nl][nm] %= mod;
                        }
                    }
                }
            }
        }
    }
    int ret = 0;
    for(int j = 0; j < 2; j++){
        for(int k = 0; k < 2; k++){
            for(int l = 0; l < 3; l++){
                if(k == 0 && l != 0)    continue;
                for(int m = 1; m < 8; m++){
                    ret += dp[n][j][k][l][m];
                    ret %= mod;
                }
            }
        }
    }
    return ret;
}

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