結果

問題 No.800 四平方定理
ユーザー leaf_1415leaf_1415
提出日時 2019-03-17 21:28:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,713 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 68,020 KB
実行使用メモリ 37,468 KB
最終ジャッジ日時 2023-09-22 03:47:06
合計ジャッジ時間 22,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,380 KB
testcase_01 AC 20 ms
4,380 KB
testcase_02 AC 14 ms
4,380 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 14 ms
4,376 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 23 ms
4,380 KB
testcase_07 AC 16 ms
4,380 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 727 ms
21,072 KB
testcase_11 AC 767 ms
36,472 KB
testcase_12 AC 812 ms
36,848 KB
testcase_13 AC 637 ms
20,828 KB
testcase_14 AC 693 ms
36,548 KB
testcase_15 AC 830 ms
36,132 KB
testcase_16 AC 700 ms
36,184 KB
testcase_17 AC 697 ms
36,172 KB
testcase_18 AC 927 ms
36,864 KB
testcase_19 AC 943 ms
36,664 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 922 ms
37,468 KB
testcase_23 AC 1,713 ms
36,836 KB
testcase_24 AC 1,362 ms
36,320 KB
testcase_25 AC 1,674 ms
35,964 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1,355 ms
37,036 KB
testcase_29 AC 1,527 ms
36,520 KB
testcase_30 AC 1,340 ms
36,004 KB
testcase_31 AC 1,232 ms
36,316 KB
testcase_32 AC 1,400 ms
36,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n, d;
vector<llint> vec;

int main(void)
{
	cin >> n >> d;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			vec.push_back(i*i-j*j);
		}
	}
	sort(vec.begin(), vec.end());
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			ans += upper_bound(vec.begin(), vec.end(), d-(i*i+j*j)) - lower_bound(vec.begin(), vec.end(), d-(i*i+j*j));
		}
	}
	cout << ans << endl;
	
	return 0;
}
0