結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-16 16:10:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,000 ms |
| コード長 | 693 bytes |
| コンパイル時間 | 1,936 ms |
| コンパイル使用メモリ | 197,708 KB |
| 最終ジャッジ日時 | 2025-01-16 01:10:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N, D; { cin >> N >> D; }
vector<int> s; {
for (int x = 1; x <= N; ++x) {
for (int y = 1; y <= N; ++y) {
s.push_back(x * x + y * y);
}
}
sort(s.begin(), s.end());
}
vector<int> pc(2000 * 2000 * 2 + 1); {
for (int v : s) pc[v] += 1;
for (int i = 1; i < pc.size(); ++i) pc[i] += pc[i - 1];
}
int64_t res = 0; {
for (int w = 1; w <= N; ++w) {
for (int z = 1; z <= N; ++z) {
int t = w * w - z * z + D;
if (t <= 0 || pc.size() <= t) continue;
res += pc[t] - pc[t - 1];
}
}
}
cout << res << endl;
}