結果
問題 | No.746 7の倍数 |
ユーザー |
![]() |
提出日時 | 2018-10-19 22:48:57 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,299 bytes |
コンパイル時間 | 663 ms |
コンパイル使用メモリ | 97,792 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-13 01:54:03 |
合計ジャッジ時間 | 1,695 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
void main() { import std.stdio, std.string, std.conv, std.algorithm; int p; rd(p); /* char[] n; n ~= "1"; foreach (_; 0 .. p) n ~= "0"; auto memo = new int[][][](n.length + 1, 2, 7); afill(memo, -1); int f(size_t i, bool less, int sum) { if (i == n.length) { return sum % 7 == 0; } else { if (memo[i][less][sum] >= 0) { return memo[i][less][sum]; } auto digit = less ? 9 : n[i] - '0'; int ret = 0; for (int d = 0; d <= digit; d++) { auto l = less || d < digit; auto s = (sum * 10 + d) % 7; ret += f(i + 1, l, s); } return memo[i][less][sum] = ret; } } writeln(f(0, 0, 0) - 1); */ if (p == 0) { writeln(0); return; } auto s = "142857"; char[] ans; ans ~= "0."; foreach (i; 0 .. p) { ans ~= s[i % s.length]; } writeln(ans); } void afill(Range, Type)(Range r, Type value) { static if (is(typeof(r) == Type[])) { foreach (ref elem; r) elem = value; } else { foreach (ref arr; r) afill(arr, value); } } void rd(T...)(ref T x) { import std.stdio : readln; import std.string : split; import std.conv : to; auto l = readln.split; assert(l.length == x.length); foreach (i, ref e; x) e = l[i].to!(typeof(e)); }