結果

問題 No.260 世界のなんとか3
ユーザー nanaenanae
提出日時 2017-06-10 16:35:06
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,911 bytes
コンパイル時間 800 ms
コンパイル使用メモリ 102,460 KB
実行使用メモリ 36,244 KB
最終ジャッジ日時 2023-09-03 14:13:15
合計ジャッジ時間 5,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 246 ms
35,964 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 65 ms
12,132 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 110 ms
17,280 KB
testcase_13 WA -
testcase_14 AC 160 ms
23,360 KB
testcase_15 AC 45 ms
8,056 KB
testcase_16 AC 141 ms
21,480 KB
testcase_17 WA -
testcase_18 AC 109 ms
16,984 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 126 ms
19,540 KB
testcase_25 AC 153 ms
18,916 KB
testcase_26 AC 96 ms
18,708 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 187 ms
34,928 KB
testcase_29 AC 301 ms
36,244 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);

    long ans = nabeatsu(b, false) - nabeatsu(a, true);

    writeln(ans);
}

long nabeatsu(string n, bool miman){
    int L = n.length.to!int;
    auto dp = new long[][][][][](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;
                        }
                    }
                }
            }
        }
    }

    long 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