結果
問題 |
No.800 四平方定理
|
ユーザー |
|
提出日時 | 2025-03-13 14:25:22 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 495 ms / 2,000 ms |
コード長 | 1,634 bytes |
コンパイル時間 | 4,579 ms |
コンパイル使用メモリ | 319,704 KB |
実行使用メモリ | 77,216 KB |
最終ジャッジ日時 | 2025-03-13 14:25:34 |
合計ジャッジ時間 | 12,477 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; #define rep1(a) for(ll i = 0; i < ll(a); i++) #define rep2(i, a) for(ll i = 0; i < ll(a); i++) #define rep3(i, a, b) for(ll i = ll(a); i < ll(b); i++) #define rep4(i, a, b, c) for(ll i = ll(a); i < ll(b); i += ll(c)) #define overload4(a, b, c, d, e, ...) e #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define all(x) begin(x),end(x) #define rall(x) rbegin(x),rend(x) #include <ext/pb_ds/assoc_container.hpp> struct splitmix64_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename K, typename V, typename Hash = splitmix64_hash> using HashMap = __gnu_pbds::gp_hash_table<K, V, Hash>; template <typename K, typename Hash = splitmix64_hash> using HashSet = HashMap<K, __gnu_pbds::null_type, Hash>; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int N, D; cin >> N >> D; HashMap<int, int> mp; rep(x, 1, N + 1) rep(y, 1, N + 1) mp[x * x + y * y]++; ll ans = 0; rep(w, 1, N + 1) rep(z, 1, N + 1) { ll val = w * w + D - z * z; if(mp.find(val) != mp.end()) ans += mp[val]; } cout << ans << endl; }