結果
問題 |
No.781 円周上の格子点の数え上げ
|
ユーザー |
|
提出日時 | 2019-01-11 22:09:24 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,020 ms / 2,000 ms |
コード長 | 1,950 bytes |
コンパイル時間 | 764 ms |
コンパイル使用メモリ | 106,200 KB |
実行使用メモリ | 206,596 KB |
最終ジャッジ日時 | 2024-06-13 02:38:18 |
合計ジャッジ時間 | 5,448 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 10L ^^ 9 + 7; void main() { int x, y; scan(x, y); int[int] sq; /* foreach (i ; 0 .. 10^^4) { sq[i*i] = i; } */ int ans; foreach (i ; 0 .. 10^^4) { foreach (j ; 0 .. i + 1) { int d = i*i + j*j; if (d < x || d > y) continue; debug { writefln("i, j, d = %d, %d, %d", i, j, d); } if (i == 0 || j == 0 || i == j) { sq[d] += 4; } else { sq[d] += 8; } ans = max(ans, sq[d]); } } /+ foreach (r ; x .. y + 1) { int tmp; foreach (i ; 0 .. r) { int d = r - i*i; if (d < 0) { break; } if (!(d in sq)) { continue; } int j = sq[d]; if (i > j) { break; } debug { writefln("(i, j) = (%d, %d)", i, j); } if (i == j || i == 0) { tmp += 4; } else { tmp += 8; } } ans = max(ans, tmp); } +/ writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); 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); } } }