結果
問題 | No.176 2種類の切手 |
ユーザー |
|
提出日時 | 2016-09-07 17:54:03 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 739 ms |
コンパイル使用メモリ | 119,480 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 04:13:38 |
合計ジャッジ時間 | 1,764 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; void main() { auto rd = readln.split.map!(to!int); auto a = rd[0], b = rd[1], t = rd[2]; writeln(calc(a, b, t)); } int calc(int a, int b, int t) { if (t % a == 0) return t; auto ca = t / a + 1; auto cb = 0; auto ct = a * ca; bool[int] memo; memo[ct - t] = true; while (ca > 0) { ca -= (ct + b - t) / a; if (ca < 0) break; cb += 1; ct = a * ca + b * cb; if ((ct - t) in memo) break; memo[ct - t] = true; } return t + memo.keys.reduce!(min); }