結果
問題 |
No.800 四平方定理
|
ユーザー |
|
提出日時 | 2024-10-04 16:02:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,075 bytes |
コンパイル時間 | 4,519 ms |
コンパイル使用メモリ | 282,620 KB |
実行使用メモリ | 69,500 KB |
最終ジャッジ日時 | 2024-10-04 16:02:29 |
合計ジャッジ時間 | 19,153 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 13 RE * 17 |
ソースコード
#include <bits/stdc++.h> using i64 = long long; constexpr int N = 1e6 + 7; int n, k; i64 cnt[N << 2]; std::vector<i64> vec; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); // freopen("alive.in", "r", stdin); // freopen("alive.out", "w", stdout); std::cin >> n >> k; memset(cnt, -1, sizeof(cnt)); for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { i64 z = 1ll * x * x - 1ll * y * y + k; vec.push_back(z); } } std::sort(vec.begin(), vec.end()); i64 ans = 0; for (int x = 1; x <= n; x++) { for (int y = 1; y <= n; y++) { i64 z = x * x + y * y; if (cnt[z] != -1) ans += cnt[z]; else { auto it0 = std::lower_bound(vec.begin(), vec.end(), z); auto it1 = std::upper_bound(vec.begin(), vec.end(), z); i64 d = it1 - it0; ans += d; cnt[z] = d; } } } std::cout << ans << "\n"; return 0; }