結果
問題 | No.800 四平方定理 |
ユーザー |
![]() |
提出日時 | 2019-03-18 18:29:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 120 ms / 2,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 1,499 ms |
コンパイル使用メモリ | 167,812 KB |
実行使用メモリ | 65,664 KB |
最終ジャッジ日時 | 2024-07-18 13:20:31 |
合計ジャッジ時間 | 3,878 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) int main() { int n,d; cin >> n >> d; int m = max(2*n*n+1,n*n+d+1); vector<int> a(m,0),b(m,0); for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) a[i*i+j*j]++; for (int i = 1;i <= n;++i) for (int j = 1;j <= n;++j) if (i*i-j*j+d > 0) b[i*i-j*j+d]++; ll ans = 0; for (int i = 1;i < m;++i) ans += a[i]*b[i]; cout << ans << endl; return 0; }