結果

問題 No.800 四平方定理
ユーザー iicafiaxusiicafiaxus
提出日時 2019-03-17 21:44:10
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,111 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 116,040 KB
実行使用メモリ 65,680 KB
最終ジャッジ日時 2023-09-03 23:47:31
合計ジャッジ時間 19,012 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,380 KB
testcase_01 AC 11 ms
4,384 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 9 ms
4,384 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 12 ms
6,148 KB
testcase_07 AC 10 ms
4,384 KB
testcase_08 AC 12 ms
6,140 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 465 ms
54,820 KB
testcase_11 AC 511 ms
57,564 KB
testcase_12 AC 487 ms
57,104 KB
testcase_13 AC 435 ms
54,628 KB
testcase_14 AC 485 ms
55,416 KB
testcase_15 AC 493 ms
57,084 KB
testcase_16 AC 569 ms
57,200 KB
testcase_17 AC 510 ms
55,528 KB
testcase_18 AC 484 ms
57,872 KB
testcase_19 AC 480 ms
57,128 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 517 ms
56,820 KB
testcase_23 AC 1,090 ms
63,664 KB
testcase_24 AC 1,098 ms
65,680 KB
testcase_25 AC 1,111 ms
63,772 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1,049 ms
63,848 KB
testcase_29 AC 1,028 ms
64,432 KB
testcase_30 AC 1,009 ms
64,688 KB
testcase_31 AC 877 ms
62,764 KB
testcase_32 AC 1,019 ms
64,040 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, k;
	foreach(x; 1 .. n + 1){
		xx = x * x;
		foreach(y; 1 .. n + 1){
			k = xx + y * y;
			if(k !in acnt) acnt[k] = 1;
			else acnt[k] += 1;
		}
	}
	
	long ans;
	long zz;
	foreach(z; 1 .. n + 1){
		zz = z * z;
		foreach(w; 1 .. n + 1){
			k = zz - w * w + d;
			if(k in acnt) ans += acnt[k];
		}
	}
	
	ans.writeln;
	
}
0