結果

問題 No.800 四平方定理
ユーザー nn1k_nn1k_
提出日時 2019-03-17 23:46:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,832 ms / 2,000 ms
コード長 2,509 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 110,212 KB
実行使用メモリ 82,428 KB
最終ジャッジ日時 2023-09-22 15:36:43
合計ジャッジ時間 25,598 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 11 ms
4,948 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 8 ms
4,504 KB
testcase_06 AC 12 ms
5,308 KB
testcase_07 AC 10 ms
4,988 KB
testcase_08 AC 13 ms
5,172 KB
testcase_09 AC 10 ms
5,272 KB
testcase_10 AC 724 ms
42,424 KB
testcase_11 AC 800 ms
61,736 KB
testcase_12 AC 767 ms
61,916 KB
testcase_13 AC 715 ms
43,716 KB
testcase_14 AC 784 ms
62,580 KB
testcase_15 AC 791 ms
62,008 KB
testcase_16 AC 807 ms
62,012 KB
testcase_17 AC 774 ms
61,692 KB
testcase_18 AC 767 ms
62,004 KB
testcase_19 AC 909 ms
63,116 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 862 ms
62,484 KB
testcase_23 AC 1,803 ms
82,012 KB
testcase_24 AC 1,707 ms
81,684 KB
testcase_25 AC 1,731 ms
81,432 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1,832 ms
82,428 KB
testcase_29 AC 1,747 ms
81,396 KB
testcase_30 AC 1,767 ms
81,160 KB
testcase_31 AC 1,576 ms
77,104 KB
testcase_32 AC 1,775 ms
81,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <limits>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_map>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <stack>
#include <string>
#include <functional>
using namespace std;

using i64 = long long;
using ui64 = unsigned long long;

using P = pair<int, int>;

constexpr int INF = (1 << 30);
constexpr std::int64_t INF64 = (1LL << 60);
constexpr int MOD = 1e9 + 7;
//constexpr std::int64_t MOD64 = 1e11 + 3;

int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

template <typename T, typename U>
static inline std::vector<U> makeNdVector(T n, U val) noexcept {
	static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
	return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}

template <typename T, typename ...Args>
static inline decltype(auto) makeNdVector(T n, Args... args) noexcept {
	static_assert(std::is_integral<T>::value, "[makeNdVector] 1st argument must be an integer type");
	return std::vector<decltype(makeNdVector(std::forward<Args>(args)...))>(std::forward<T>(n), makeNdVector(std::forward<Args>(args)...));
}

template <typename T>
void print(vector<T> vec)
{
	for (auto &e : vec)
		cout << e << " ";
	cout << endl;
}

void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
void yes(bool f) { cout << (f ? "yes" : "no") << endl; }

template <typename T>
T gcd(T x, T y) {
	if (x == 0 || y == 0) return 0;
	T r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}

template <typename T>
T lcm(T x, T y) {
	if (x == 0 || y == 0) return 0;
	return (x / gcd(x, y) * y);
}

int next_combination(int sub)
{
	int x = sub & -sub, y = sub + x;
	return (((sub & ~y) / x) >> 1) | y;
}

std::uint64_t combination(int n, int r) {
	if (n < 0 || r < 0) return 0;
	if (n < r) return 0;
	std::uint64_t k = 1;
	for (std::uint64_t d = 1; d <= r; ++d) {
		k *= n--;
		k /= d;
	}
	return k;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	using P = pair<int, int>;

	i64 N, D; cin >> N >> D;

	unordered_map<i64, i64> left;
	vector<i64> right;
	for (i64 x = 1; x <= N; ++x) {
		for (i64 y = 1; y <= N; ++y) {
			left[x * x + y * y]++;
			right.emplace_back(D - x * x + y * y);
		}
	}

	i64 ans = 0;
	for (int i = 0; i < right.size(); ++i) {
		if (left.count(right[i]) == 0) continue;
		else ans += left[right[i]];
	}

	cout << ans << endl;
}
0