結果

問題 No.800 四平方定理
ユーザー aa
提出日時 2019-03-17 22:06:40
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 1,308 ms
使用メモリ 34,412 KB
最終ジャッジ日時 2023-02-11 07:24:58
合計ジャッジ時間 3,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
6,948 KB
testcase_01 AC 2 ms
4,900 KB
testcase_02 AC 2 ms
4,900 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 1 ms
4,900 KB
testcase_05 AC 2 ms
4,900 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 2 ms
4,900 KB
testcase_09 AC 2 ms
4,908 KB
testcase_10 AC 16 ms
18,404 KB
testcase_11 AC 19 ms
20,440 KB
testcase_12 AC 17 ms
20,188 KB
testcase_13 AC 14 ms
19,264 KB
testcase_14 AC 16 ms
20,460 KB
testcase_15 AC 17 ms
20,252 KB
testcase_16 AC 17 ms
20,600 KB
testcase_17 AC 16 ms
20,680 KB
testcase_18 AC 19 ms
20,604 KB
testcase_19 AC 19 ms
20,564 KB
testcase_20 AC 1 ms
4,900 KB
testcase_21 AC 1 ms
4,900 KB
testcase_22 AC 21 ms
20,572 KB
testcase_23 AC 49 ms
34,176 KB
testcase_24 AC 43 ms
34,364 KB
testcase_25 AC 51 ms
34,220 KB
testcase_26 AC 1 ms
6,948 KB
testcase_27 AC 1 ms
4,900 KB
testcase_28 AC 44 ms
34,060 KB
testcase_29 AC 44 ms
34,244 KB
testcase_30 AC 38 ms
34,060 KB
testcase_31 AC 35 ms
32,008 KB
testcase_32 AC 40 ms
34,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N, D, ans = 0;
	cin >> N >> D;
	vector<int> mp(N*N*2+1);
	for (int y = 1; y <= N; y++)
	{
		for (int z = 1; z <= N; z++)
		{
			int s = y*y+z*z;
			if (s<=N*N*2) mp[s]++;
		}
	}

	for (int x = 1; x <= N; x++)
	{
		for (int w = 1; w <= N; w++)
		{
			int p = D + w * w - x * x;
			if (p > N*N*2 || p < 0) continue;
			ans += mp[p];
		}
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0