結果

問題 No.800 四平方定理
ユーザー Jiro_tech15Jiro_tech15
提出日時 2019-03-22 18:48:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 662 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 89,352 KB
実行使用メモリ 65,748 KB
最終ジャッジ日時 2023-10-19 06:12:05
合計ジャッジ時間 11,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,348 KB
testcase_01 AC 13 ms
4,740 KB
testcase_02 AC 9 ms
4,348 KB
testcase_03 AC 10 ms
4,348 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 10 ms
4,348 KB
testcase_06 AC 14 ms
4,740 KB
testcase_07 AC 11 ms
4,740 KB
testcase_08 AC 15 ms
4,740 KB
testcase_09 AC 13 ms
4,740 KB
testcase_10 AC 315 ms
34,340 KB
testcase_11 AC 368 ms
54,256 KB
testcase_12 AC 361 ms
53,436 KB
testcase_13 AC 330 ms
35,660 KB
testcase_14 AC 378 ms
53,512 KB
testcase_15 AC 364 ms
54,256 KB
testcase_16 AC 371 ms
52,632 KB
testcase_17 AC 370 ms
53,512 KB
testcase_18 AC 368 ms
54,256 KB
testcase_19 AC 374 ms
52,632 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 375 ms
53,512 KB
testcase_23 AC 662 ms
65,748 KB
testcase_24 AC 654 ms
65,748 KB
testcase_25 AC 653 ms
65,748 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 646 ms
65,484 KB
testcase_29 AC 651 ms
65,748 KB
testcase_30 AC 648 ms
65,484 KB
testcase_31 AC 610 ms
61,260 KB
testcase_32 AC 656 ms
65,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


int main(void){
	ll n,d;
	cin>>n>>d;
	vector<ll> xy,zw;
	reps(i,n){
		reps(j,n){
			xy.push_back(i*i+j*j);
			zw.push_back(i*i-j*j+d);
		}
	}
	sort(xy.begin(),xy.end());
	sort(zw.begin(),zw.end());
	int xi=0,zi=0;
	ll ans = 0;
	while(xi < n*n && zi < n*n){
		ll memo = 0;
		for(;zi < n*n && zw[zi] <= xy[xi];zi++){
			if(zw[zi] == xy[xi]){
				memo++;
			}
		}
		ll memo2 = 1;
		for(;xi+1 < n*n && xy[xi] == xy[xi+1];){
			xi++;
			memo2++;
		}
		ans += memo * memo2;
		xi++;
	}
	cout<<ans<<endl;

	
	return 0;
}
0