結果

問題 No.800 四平方定理
ユーザー e869120e869120
提出日時 2019-05-15 21:15:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 924 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 75,740 KB
実行使用メモリ 34,764 KB
最終ジャッジ日時 2023-10-12 14:17:18
合計ジャッジ時間 15,846 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,352 KB
testcase_01 AC 17 ms
4,348 KB
testcase_02 AC 12 ms
4,348 KB
testcase_03 AC 12 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 13 ms
4,348 KB
testcase_06 AC 19 ms
4,348 KB
testcase_07 AC 15 ms
4,348 KB
testcase_08 AC 17 ms
4,348 KB
testcase_09 AC 17 ms
4,352 KB
testcase_10 AC 448 ms
18,672 KB
testcase_11 AC 500 ms
28,944 KB
testcase_12 AC 500 ms
28,492 KB
testcase_13 AC 453 ms
19,372 KB
testcase_14 AC 491 ms
29,124 KB
testcase_15 AC 505 ms
29,276 KB
testcase_16 AC 495 ms
31,096 KB
testcase_17 AC 499 ms
30,764 KB
testcase_18 AC 525 ms
28,436 KB
testcase_19 AC 524 ms
28,484 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 524 ms
28,028 KB
testcase_23 AC 924 ms
34,464 KB
testcase_24 AC 883 ms
34,372 KB
testcase_25 AC 921 ms
34,764 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 876 ms
34,444 KB
testcase_29 AC 896 ms
34,544 KB
testcase_30 AC 879 ms
34,416 KB
testcase_31 AC 816 ms
32,808 KB
testcase_32 AC 893 ms
34,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long N, D, sum; vector<int>E1, E2;

int main() {
	cin >> N >> D;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			E1.push_back(i*i + j * j);
			E2.push_back(i*i - j * j);
		}
	}
	sort(E1.begin(), E1.end());
	sort(E2.begin(), E2.end());

	for (int i = 0; i < E1.size(); i++) {
		int target = D - E1[i];
		int pos1 = lower_bound(E2.begin(), E2.end(), target) - E2.begin();
		int pos2 = lower_bound(E2.begin(), E2.end(), target + 1) - E2.begin();
		sum += 1LL * (pos2 - pos1);
	}
	cout << sum << endl;
	return 0;
}
0