結果

問題 No.800 四平方定理
ユーザー Akidai16
提出日時 2021-05-09 20:41:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 4,070 ms
コンパイル使用メモリ 228,352 KB
実行使用メモリ 34,560 KB
最終ジャッジ日時 2024-09-19 01:29:07
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int N, D;
vi x2y2;

void solve() {
    x2y2.resize(2000 * 2000 * 2 + 1);
    REP(x, 1, N + 1) {
        REP(y, 1, N + 1) {
            int total = x * x + y * y;
            x2y2[total]++;
        }
    }
    long ans = 0;
    REP(w, 1, N + 1) {
        REP(z, 1, N + 1) {
            int search = D + w * w - z * z; 
            if(search <= 0) continue;
            ans += x2y2[search];
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N >> D;
    solve();
}
0