結果

問題 No.800 四平方定理
ユーザー iicafiaxusiicafiaxus
提出日時 2019-03-17 21:38:17
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,771 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 118,168 KB
実行使用メモリ 140,512 KB
最終ジャッジ日時 2023-09-03 23:47:04
合計ジャッジ時間 24,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 15 ms
5,896 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 11 ms
4,428 KB
testcase_04 AC 11 ms
4,432 KB
testcase_05 AC 12 ms
4,424 KB
testcase_06 AC 18 ms
6,404 KB
testcase_07 AC 18 ms
6,704 KB
testcase_08 AC 27 ms
13,400 KB
testcase_09 AC 15 ms
4,640 KB
testcase_10 AC 836 ms
106,528 KB
testcase_11 AC 880 ms
107,488 KB
testcase_12 AC 928 ms
108,432 KB
testcase_13 AC 773 ms
104,232 KB
testcase_14 AC 810 ms
106,788 KB
testcase_15 AC 936 ms
109,756 KB
testcase_16 AC 821 ms
106,400 KB
testcase_17 AC 828 ms
108,364 KB
testcase_18 AC 1,002 ms
111,836 KB
testcase_19 AC 999 ms
112,060 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1,030 ms
113,012 KB
testcase_23 AC 1,750 ms
139,284 KB
testcase_24 AC 1,462 ms
134,228 KB
testcase_25 AC 1,771 ms
140,512 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1,450 ms
133,344 KB
testcase_29 AC 1,601 ms
136,740 KB
testcase_30 AC 1,481 ms
134,348 KB
testcase_31 AC 1,323 ms
131,708 KB
testcase_32 AC 1,507 ms
136,420 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