結果
問題 | No.800 四平方定理 |
ユーザー |
![]() |
提出日時 | 2019-03-17 21:38:17 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,447 ms / 2,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 1,335 ms |
コンパイル使用メモリ | 129,172 KB |
実行使用メモリ | 136,580 KB |
最終ジャッジ日時 | 2024-06-13 04:19:12 |
合計ジャッジ時間 | 20,281 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
import std.stdio, std.conv, std.string; import std.array, std.range, std.algorithm, std.container; import std.math, std.random, std.bigint, std.datetime, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } int DEBUG_LEVEL = 0; void print()(){ writeln(""); } void print(T, A ...)(T t, lazy A a){ write(t), print(a); } void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); } void main(string[] args){ if(args.length > 1 && args[1] == "-debug"){ if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int; else DEBUG_LEVEL = 1; } /* xx + yy をカウント ww - zz + D をカウント *0以上のもののみ */ long n = read.to!long; long d = read.to!long; long[long] acnt, bcnt; long xx, yy, ak; foreach(x; 1 .. n + 1){ xx = x * x; foreach(y; 1 .. n + 1){ ak = xx + y * y; if(ak !in acnt) acnt[ak] = 0; acnt[ak] += 1; } } long zz, ww, bk; foreach(z; 1 .. n + 1){ zz = z * z; foreach(w; 1 .. n + 1){ bk = zz - w * w + d; if(bk > 0){ if(bk !in bcnt) bcnt[bk] = 0; bcnt[bk] += 1; } } } long ans; foreach(k; acnt.keys){ if(k in bcnt) ans += acnt[k] * bcnt[k]; } ans.writeln; }