結果

問題 No.473 和と積の和
ユーザー yosupotyosupot
提出日時 2016-12-24 16:24:11
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 302 ms / 3,000 ms
コード長 2,271 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 89,920 KB
実行使用メモリ 60,000 KB
最終ジャッジ日時 2023-09-03 00:06:36
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 49 ms
24,196 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 170 ms
60,000 KB
testcase_26 AC 40 ms
24,188 KB
testcase_27 AC 57 ms
24,196 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 96 ms
37,520 KB
testcase_35 AC 83 ms
37,500 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 77 ms
37,580 KB
testcase_39 AC 42 ms
24,140 KB
testcase_40 AC 43 ms
24,128 KB
testcase_41 AC 302 ms
27,204 KB
testcase_42 AC 49 ms
37,508 KB
testcase_43 AC 61 ms
43,964 KB
testcase_44 AC 74 ms
53,980 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/+ dub.sdl:
	name "A"
	dependency "dcomp" version=">=0.0.2"
+/
import std.stdio, std.conv, std.algorithm;
// import dcomp.scanner;

Scanner sc;
static this() {sc = new Scanner();}

int[] divlist;
int[][] nx;

int main() {
    int N, X;
    sc.read(N, X);
    X++;

    for (int i = 1; i*i <= X; i++) {
        if (X % i == 0) {
            divlist ~= i;
            if (i*i != X) divlist ~= X/i;
        }
    }
    sort(divlist);
    int M = divlist.length.to!int;
    int[int] p2id;
    foreach (i, d; divlist) {
        p2id[d] = i.to!int;
    }
    nx = new int[][](M, M);
    foreach (i; 0..M) {
        foreach(j; 0..M) {
            int A = divlist[i];
            int B = divlist[j];
            if (A % B) {
                nx[i][j] = -1;
            } else {
                nx[i][j] = p2id[A/B];
            }
        }
    }

    auto dp1 = new int[][](M, M);
    dp1[0][] = 1;
    foreach (fe; 0..N) {
        auto dp2 = new int[][](M, M);
        foreach (i; 0..M) {
            foreach_reverse (j; 0..M) {
                if (j < M-1) dp2[i][j] += dp2[i][j+1];
                if (nx[i][j] != -1) dp2[i][j] += dp1[nx[i][j]][j];
            }
        }
        dp1 = dp2;
    }
    writeln(dp1[M-1][1]);
	return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, readln, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeString, isDynamicArray;
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = readln.split;
        }
        return true;
    }
    int read(Args...)(auto ref Args args) {
        foreach (i, ref v; args) {
            if (!succ()) return i;
            alias VT = typeof(v);
            static if (!isSomeString!VT && isDynamicArray!VT) {
                v = buf.map!(to!(ElementType!VT)).array;
                buf.length = 0;
            } else {
                v = buf.front.to!VT;
                buf.popFront();
            }
        }
        return args.length;
    }
}
0