結果
| 問題 |
No.473 和と積の和
|
| コンテスト | |
| ユーザー |
yosupot
|
| 提出日時 | 2016-12-24 16:24:11 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 3,000 ms |
| コード長 | 2,271 bytes |
| コンパイル時間 | 932 ms |
| コンパイル使用メモリ | 103,852 KB |
| 実行使用メモリ | 59,616 KB |
| 最終ジャッジ日時 | 2024-06-12 06:03:41 |
| 合計ジャッジ時間 | 3,073 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
/+ 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;
}
}
yosupot