結果

問題 No.800 四平方定理
ユーザー wacchozwacchoz
提出日時 2019-03-17 21:31:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,004 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 150,132 KB
実行使用メモリ 84,472 KB
最終ジャッジ日時 2023-09-22 04:00:09
合計ジャッジ時間 16,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,376 KB
testcase_01 AC 18 ms
5,096 KB
testcase_02 AC 13 ms
4,376 KB
testcase_03 AC 14 ms
4,376 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 14 ms
4,392 KB
testcase_06 AC 20 ms
5,604 KB
testcase_07 AC 15 ms
5,016 KB
testcase_08 AC 17 ms
5,424 KB
testcase_09 AC 19 ms
5,160 KB
testcase_10 AC 466 ms
43,456 KB
testcase_11 AC 530 ms
70,904 KB
testcase_12 AC 525 ms
70,008 KB
testcase_13 AC 478 ms
44,636 KB
testcase_14 AC 523 ms
70,716 KB
testcase_15 AC 531 ms
71,020 KB
testcase_16 AC 527 ms
72,252 KB
testcase_17 AC 528 ms
72,308 KB
testcase_18 AC 550 ms
70,632 KB
testcase_19 AC 548 ms
71,636 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 553 ms
70,924 KB
testcase_23 AC 970 ms
83,604 KB
testcase_24 AC 935 ms
83,980 KB
testcase_25 AC 960 ms
83,852 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 930 ms
83,652 KB
testcase_29 AC 946 ms
83,368 KB
testcase_30 AC 1,004 ms
84,472 KB
testcase_31 AC 860 ms
83,212 KB
testcase_32 AC 941 ms
84,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;


signed main(){

	int N, D;
	cin >> N >> D;

	vector<int> add, sub;

	for (int x = 1; x <= N; x++){
		for (int y = 1; y <= N; y++){
			add.push_back(x*x + y*y);
		}
	}
	for (int w = 1; w <= N; w++){
		for (int z = 1; z <= N; z++){
			sub.push_back(w*w -z*z + D);
		}
	}
	sort(add.begin(), add.end());
	sort(sub.begin(), sub.end());

	int ans = 0;
	for (int l : add){
		ans += upper_bound(sub.begin(), sub.end(), l)
			- lower_bound(sub.begin(), sub.end(), l);
	}

	cout << ans << endl;

	return 0;
}
0