結果

問題 No.800 四平方定理
ユーザー iicafiaxusiicafiaxus
提出日時 2019-03-17 21:38:17
言語 D
(dmd 2.099.1)
結果
AC  
実行時間 1,363 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 1,255 ms
使用メモリ 139,204 KB
最終ジャッジ日時 2023-02-11 05:03:59
合計ジャッジ時間 20,617 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 8 ms
4,912 KB
testcase_01 AC 15 ms
5,300 KB
testcase_02 AC 11 ms
6,948 KB
testcase_03 AC 11 ms
6,948 KB
testcase_04 AC 11 ms
5,200 KB
testcase_05 AC 12 ms
5,044 KB
testcase_06 AC 17 ms
7,248 KB
testcase_07 AC 17 ms
8,272 KB
testcase_08 AC 25 ms
10,784 KB
testcase_09 AC 15 ms
5,464 KB
testcase_10 AC 713 ms
104,656 KB
testcase_11 AC 746 ms
106,232 KB
testcase_12 AC 813 ms
107,688 KB
testcase_13 AC 606 ms
102,984 KB
testcase_14 AC 655 ms
104,408 KB
testcase_15 AC 696 ms
107,744 KB
testcase_16 AC 615 ms
104,788 KB
testcase_17 AC 622 ms
104,752 KB
testcase_18 AC 743 ms
110,304 KB
testcase_19 AC 732 ms
110,332 KB
testcase_20 AC 1 ms
6,948 KB
testcase_21 AC 1 ms
6,948 KB
testcase_22 AC 760 ms
110,412 KB
testcase_23 AC 1,341 ms
139,204 KB
testcase_24 AC 1,145 ms
132,888 KB
testcase_25 AC 1,363 ms
138,160 KB
testcase_26 AC 1 ms
4,904 KB
testcase_27 AC 1 ms
4,900 KB
testcase_28 AC 1,190 ms
133,192 KB
testcase_29 AC 1,289 ms
135,888 KB
testcase_30 AC 1,159 ms
132,260 KB
testcase_31 AC 1,034 ms
128,448 KB
testcase_32 AC 1,202 ms
133,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	
}
0