結果

問題 No.800 四平方定理
ユーザー misora192
提出日時 2020-05-15 09:08:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 668 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 175,148 KB
実行使用メモリ 56,064 KB
最終ジャッジ日時 2024-09-17 15:14:00
合計ジャッジ時間 8,764 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 10 TLE * 11 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, d;
	cin >> n >> d;

	map<int, int> mp;
	rep(z, n) rep(w, n){
		int a = (w + 1) * (w + 1) - (z + 1) * (z + 1) + d;
		if(mp.count(a) == 0) mp[a] = 0;
		mp[a]++;
	}

	int ans = 0;
	rep(x, n) rep(y, n){
		int a = (x + 1) * (x + 1) + (y + 1) * (y + 1);
		if(mp.count(a) > 0) ans += mp[a];
	}

	cout << ans << endl;
}
0