結果

問題 No.800 四平方定理
ユーザー ty70ty70
提出日時 2019-03-18 00:35:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 1,219 ms
コンパイル使用メモリ 143,592 KB
実行使用メモリ 81,800 KB
最終ジャッジ日時 2023-09-22 16:16:34
合計ジャッジ時間 4,047 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
81,548 KB
testcase_01 AC 35 ms
81,604 KB
testcase_02 AC 35 ms
81,792 KB
testcase_03 AC 36 ms
81,532 KB
testcase_04 AC 35 ms
81,500 KB
testcase_05 AC 35 ms
81,652 KB
testcase_06 AC 35 ms
81,512 KB
testcase_07 AC 37 ms
81,544 KB
testcase_08 AC 36 ms
81,544 KB
testcase_09 AC 35 ms
81,660 KB
testcase_10 AC 53 ms
81,492 KB
testcase_11 AC 54 ms
81,532 KB
testcase_12 AC 55 ms
81,528 KB
testcase_13 AC 50 ms
81,484 KB
testcase_14 AC 53 ms
81,484 KB
testcase_15 AC 53 ms
81,656 KB
testcase_16 AC 53 ms
81,656 KB
testcase_17 AC 53 ms
81,544 KB
testcase_18 AC 56 ms
81,500 KB
testcase_19 AC 55 ms
81,768 KB
testcase_20 AC 34 ms
81,532 KB
testcase_21 AC 35 ms
81,600 KB
testcase_22 AC 57 ms
81,800 KB
testcase_23 AC 88 ms
81,488 KB
testcase_24 AC 84 ms
81,756 KB
testcase_25 AC 87 ms
81,536 KB
testcase_26 AC 34 ms
81,496 KB
testcase_27 AC 36 ms
81,492 KB
testcase_28 AC 85 ms
81,556 KB
testcase_29 AC 86 ms
81,496 KB
testcase_30 AC 86 ms
81,596 KB
testcase_31 AC 80 ms
81,528 KB
testcase_32 AC 88 ms
81,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;

const int MAX_N2 = (int)1e7;
int cnt1[MAX_N2];
int cnt2[MAX_N2];
	
int main()
{
	memset(cnt1, 0, sizeof(cnt1));
	memset(cnt2, 0, sizeof(cnt2));

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, D; cin >> N >> D;

	for (int x = 1; x <= N; ++x){
		for (int y = 1; y <= N; ++y){
			++cnt1[x*x + y*y];
		} // end for
	} // end for

	for (int w = 1; w <= N; ++w){
		for (int z = 1; z <= N; ++z){
			int i = w * w - z * z + D;
			if (i >= 0){
				++cnt2[i];
			} // end if
		} // end for
	} // end for

	ll res = 0LL;
	rep (i, MAX_N2){
		res += (ll)cnt1[i] * cnt2[i];
	} // end rep
	cout << res << endl;

	return 0;
}
0