結果

問題 No.800 四平方定理
ユーザー startcppstartcpp
提出日時 2019-03-17 22:38:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 51,776 KB
実行使用メモリ 107,980 KB
最終ジャッジ日時 2023-09-22 08:31:08
合計ジャッジ時間 2,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,644 KB
testcase_01 AC 4 ms
8,160 KB
testcase_02 AC 3 ms
5,860 KB
testcase_03 AC 3 ms
5,816 KB
testcase_04 AC 2 ms
5,792 KB
testcase_05 AC 2 ms
5,896 KB
testcase_06 AC 3 ms
8,132 KB
testcase_07 AC 3 ms
8,244 KB
testcase_08 AC 3 ms
7,384 KB
testcase_09 AC 3 ms
8,232 KB
testcase_10 AC 41 ms
56,688 KB
testcase_11 AC 42 ms
60,728 KB
testcase_12 AC 44 ms
62,680 KB
testcase_13 AC 36 ms
54,580 KB
testcase_14 AC 38 ms
58,696 KB
testcase_15 AC 42 ms
62,724 KB
testcase_16 AC 33 ms
58,584 KB
testcase_17 AC 36 ms
58,572 KB
testcase_18 AC 45 ms
66,848 KB
testcase_19 AC 44 ms
66,820 KB
testcase_20 AC 2 ms
5,424 KB
testcase_21 AC 2 ms
5,388 KB
testcase_22 AC 43 ms
66,776 KB
testcase_23 AC 78 ms
107,980 KB
testcase_24 AC 75 ms
99,788 KB
testcase_25 AC 79 ms
107,836 KB
testcase_26 AC 2 ms
5,412 KB
testcase_27 AC 2 ms
5,352 KB
testcase_28 AC 69 ms
99,588 KB
testcase_29 AC 73 ms
103,712 KB
testcase_30 AC 67 ms
99,620 KB
testcase_31 AC 69 ms
93,512 KB
testcase_32 AC 76 ms
99,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define int long long
using namespace std;

int cnt1[8000001];	//x^2 + y^2
int cnt2[8000001];	//z^2 - w^2 + D
int n, d;

signed main() {
	int i, j;
	
	cin >> n >> d;
	
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			cnt1[i * i + j * j]++;
	
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			int x = i * i - j * j + d;
			if (0 <= x && x <= 2 * n * n) {
				cnt2[x]++;
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i <= 2 * n * n; i++)
		ans += cnt1[i] * cnt2[i];
	cout << ans << endl;
	return 0;
}
0