結果
問題 | No.800 四平方定理 |
ユーザー | wacchoz |
提出日時 | 2019-03-17 21:31:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 832 ms / 2,000 ms |
コード長 | 858 bytes |
コンパイル時間 | 1,362 ms |
コンパイル使用メモリ | 164,544 KB |
実行使用メモリ | 84,620 KB |
最終ジャッジ日時 | 2024-07-07 20:47:08 |
合計ジャッジ時間 | 14,203 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define int long long #define ll long long typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL<<60) #define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; signed main(){ int N, D; cin >> N >> D; vector<int> add, sub; for (int x = 1; x <= N; x++){ for (int y = 1; y <= N; y++){ add.push_back(x*x + y*y); } } for (int w = 1; w <= N; w++){ for (int z = 1; z <= N; z++){ sub.push_back(w*w -z*z + D); } } sort(add.begin(), add.end()); sort(sub.begin(), sub.end()); int ans = 0; for (int l : add){ ans += upper_bound(sub.begin(), sub.end(), l) - lower_bound(sub.begin(), sub.end(), l); } cout << ans << endl; return 0; }