結果

問題 No.260 世界のなんとか3
ユーザー nanaenanae
提出日時 2017-06-10 16:41:42
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,922 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 102,204 KB
実行使用メモリ 24,272 KB
最終ジャッジ日時 2023-09-03 14:14:06
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 246 ms
24,272 KB
testcase_04 AC 247 ms
23,732 KB
testcase_05 AC 46 ms
6,428 KB
testcase_06 AC 32 ms
6,096 KB
testcase_07 AC 171 ms
16,548 KB
testcase_08 AC 115 ms
13,824 KB
testcase_09 AC 66 ms
8,016 KB
testcase_10 AC 190 ms
18,912 KB
testcase_11 AC 179 ms
17,148 KB
testcase_12 AC 106 ms
11,288 KB
testcase_13 AC 29 ms
5,076 KB
testcase_14 AC 165 ms
15,696 KB
testcase_15 AC 42 ms
5,956 KB
testcase_16 AC 138 ms
13,824 KB
testcase_17 AC 110 ms
12,344 KB
testcase_18 AC 106 ms
11,832 KB
testcase_19 AC 137 ms
13,856 KB
testcase_20 AC 97 ms
11,348 KB
testcase_21 AC 87 ms
11,068 KB
testcase_22 AC 165 ms
15,712 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 123 ms
12,872 KB
testcase_25 AC 150 ms
13,080 KB
testcase_26 AC 93 ms
12,844 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 188 ms
23,724 KB
testcase_29 AC 302 ms
23,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;

void main(){
    string a, b;
    readVars(a, b);

    int ans = (nabeatsu(b, false) - nabeatsu(a, true) + mod) % mod;

    writeln(ans);
}

long nabeatsu(string n, bool miman){
    int L = n.length.to!int;
    auto dp = new int[][][][][](L + 1, 2, 2, 3, 8);
    dp[0][0][0][0][0] = 1;

    foreach(i ; 0 .. L){
        foreach(j ; 0 .. 2){
            foreach(k ; 0 .. 2){
                foreach(l ; 0 .. 3){
                    foreach(m ; 0 .. 8){
                        for(int d = 0; d <= (j ? 9 : n[i] - '0'); d++){
                            (dp[i + 1][j || (d < n[i] - '0')][k || (d == 3)][(l + d) % 3][(10*m + d) % 8] += dp[i][j][k][l][m]) %= mod;
                        }
                    }
                }
            }
        }
    }

    int ans;

    if (miman) {
       foreach(k ; 0 .. 2){
            foreach(l ; 0 .. 3){
                foreach(m ; 0 .. 8){
                    if ((k || (l == 0)) && (m != 0)){
                        (ans += dp[L][1][k][l][m]) %= mod;
                    }
                }
            }
        } 
    }
    else {
        foreach(j ; 0 .. 2){
            foreach(k ; 0 .. 2){
                foreach(l ; 0 .. 3){
                    foreach(m ; 0 .. 8){
                        if ((k || (l == 0)) && (m != 0)){
                            (ans += dp[L][j][k][l][m]) %= mod;
                        }
                    }
                }
            }
        }
    }
    return ans;
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}
0