結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-05 01:31:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,419 ms / 2,000 ms |
| コード長 | 659 bytes |
| コンパイル時間 | 2,061 ms |
| コンパイル使用メモリ | 199,164 KB |
| 最終ジャッジ日時 | 2025-01-14 06:38:27 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d;
cin >> n >> d;
vector<int> p, q;
for (int x = 1; x <= n; x++) {
for (int y = 1; y <= n; y++) {
p.push_back(x*x + y*y);
}
}
for (int z = 1; z <= n; z++) {
for (int w = 1; w <= n; w++) {
q.push_back(z*z - w*w);
}
}
sort(q.begin(), q.end());
long long ret = 0;
for (int x: p) {
int target = d - x;
ret += upper_bound(q.begin(), q.end(), target)
- lower_bound(q.begin(), q.end(), target);
}
cout << ret << endl;
return 0;
}