結果
問題 |
No.1010 折って重ねて
|
ユーザー |
|
提出日時 | 2020-03-20 21:36:57 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,628 bytes |
コンパイル時間 | 764 ms |
コンパイル使用メモリ | 113,920 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 05:44:22 |
合計ジャッジ時間 | 1,862 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
import std.stdio, std.string, std.conv, std.range; import std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, std.random, core.bitop; enum inf = 1_001_001_001; enum infl = 1_001_001_001_001_001_001L; alias Trip = Tuple!(long, "x", long, "y", long, "h"); void main() { long x, y, h; scan(x, y, h); x *= 1000; y *= 1000; int[Trip] dp; int rec(long x, long y, long h) { auto tr = Trip(x, y, h); if (tr in dp) { return dp[tr]; } dp[tr] = 0; if (x > h) { chmax(dp[tr], rec((x + 1) / 2, y, 2*h) + 1); } if (y > h) { chmax(dp[tr], rec(x, (y + 1) / 2, 2*h) + 1); } return dp[tr]; } auto ans = rec(x, y, h); writeln(ans); } void scan(T...)(ref T args) { auto line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront; } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x > arg) { x = arg; isChanged = true; } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) if (x < arg) { x = arg; isChanged = true; } return isChanged; } void yes(bool ok, string y = "Yes", string n = "No") { return writeln(ok ? y : n); }