結果

問題 No.800 四平方定理
コンテスト
ユーザー vjudge1
提出日時 2026-03-10 18:32:49
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,455 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,547 ms
コンパイル使用メモリ 206,012 KB
実行使用メモリ 66,052 KB
最終ジャッジ日時 2026-03-10 18:32:55
合計ジャッジ時間 5,484 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define ii pair<ll, ll>
using ll = long long int;
#define pb push_back
#define ss second
#define ff first
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define nl "\n"
#define br cout << "\n";
#define all(a) a.begin(), a.end()
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
// #define mod 419
// #define mod 1000000007
// #define mod 10000000002065383
const int N = 2e5 + 100;
// const int M = 1000000000;

#ifndef ONLINE_JUDGE
#include "bits/debug.h"
#else
#define debug(...) 42
#endif

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (auto& elem : v) {
        in >> elem;
    }
    return in;
}

void print(vi &v)
{
    for (auto x : v)
        cout << x << " ";
    cout << endl;
}

void solve() {
    ll n,d; cin >> n >> d;
    ll N = 4e6 + 200;
    vector<ll>  mpa(N),mpb(N);

    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            ll a = i*i + j*j;
            ll b = i*i - j*j + d;

            if(a<N)  mpa[a] ++;
            if(b>0 &&  b<N) mpb[b]++;
        }
    }

    ll ans = 0;
    for(ll i =1; i <N ;i++){
        ans += mpa[i] * mpb[i];
    }
    cout << ans << nl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int Test = 1;
    // cin >> Test;

    while (Test--) 
    {
        solve();
    }
    return 0;
}
0