結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
nomi
|
| 提出日時 | 2019-03-18 00:32:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 730 bytes |
| コンパイル時間 | 1,569 ms |
| コンパイル使用メモリ | 165,800 KB |
| 実行使用メモリ | 64,384 KB |
| 最終ジャッジ日時 | 2024-07-08 07:48:05 |
| 合計ジャッジ時間 | 3,702 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N, D;
int XY[2*2000*2000+100]; // XY[i]: 左辺がiになる組み合わせの数
signed main() {
cin >> N >> D;
// 左辺 (x^2 + y^2) の組み合わせを数える
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
int left = x*x + y*y;
XY[left]++;
}
}
int ans = 0;
// 右辺 (w^2 - z^2 + D) の組み合わせを数える
for (int w = 1; w <= N; w++) {
for (int z = 1; z <= N; z++) {
int right = w*w - z*z + D;
// 左辺の値の範囲は 2 <= (x^2 + y^2) <= 2*N^2
if (2 <= right and right <= 2*N*N) {
ans += XY[right];
}
}
}
cout << ans << endl;
return 0;
}
nomi