結果

問題 No.800 四平方定理
ユーザー brightcat_coderbrightcat_coder
提出日時 2019-04-20 14:55:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 4,147 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 170,560 KB
実行使用メモリ 74,988 KB
最終ジャッジ日時 2024-04-08 16:30:22
合計ジャッジ時間 3,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,908 KB
testcase_01 AC 4 ms
8,088 KB
testcase_02 AC 3 ms
7,964 KB
testcase_03 AC 4 ms
7,988 KB
testcase_04 AC 4 ms
7,976 KB
testcase_05 AC 4 ms
8,008 KB
testcase_06 AC 5 ms
8,192 KB
testcase_07 AC 4 ms
8,168 KB
testcase_08 AC 5 ms
9,892 KB
testcase_09 AC 4 ms
8,104 KB
testcase_10 AC 37 ms
40,472 KB
testcase_11 AC 42 ms
43,480 KB
testcase_12 AC 40 ms
43,332 KB
testcase_13 AC 34 ms
38,792 KB
testcase_14 AC 35 ms
41,432 KB
testcase_15 AC 49 ms
43,424 KB
testcase_16 AC 39 ms
41,528 KB
testcase_17 AC 35 ms
41,528 KB
testcase_18 AC 46 ms
45,588 KB
testcase_19 AC 41 ms
45,600 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 43 ms
45,624 KB
testcase_23 AC 81 ms
74,988 KB
testcase_24 AC 75 ms
70,892 KB
testcase_25 AC 83 ms
74,940 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 75 ms
70,812 KB
testcase_29 AC 79 ms
72,908 KB
testcase_30 AC 71 ms
70,828 KB
testcase_31 AC 66 ms
65,644 KB
testcase_32 AC 71 ms
70,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(ll i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> int former(const vector<T> &v, T x){
   return upper_bound(v.begin(),v.end(),x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(),v.end(),x) - v.begin();
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<29;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }

    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(ll x) {
        return -par[root(x)];
    }
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T> > > & G){
   const T INF = numeric_limits<T>::max();
   using P = pair<T, int>;
   int n=G.size();
   vector<T> d(n,INF);
   vector<int> b(n,-1);
   priority_queue<P,vector<P>,greater<P> > q;
   d[s]=0;
   q.emplace(d[s],s);
   while(!q.empty()){
     P p=q.top();q.pop();
     int v=p.second;
     if(d[v]<p.first) continue;
     for(auto& e:G[v]){
       int u=e.first;
       T c=e.second;
       if(d[u]>d[v]+c){
         d[u]=d[v]+c;
         b[u]=v;
         q.emplace(d[u],u);
       }
     }
   }
   return d;
}

const int dx[4] = {1, 0, -1, 0}; // const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[4] = {0, 1, 0, -1}; // const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int XY[2*2000*2000+100]; // XY[i]: 左辺がiになる組み合わせの数
int WZ[2*2000*2000+100]; // WZ[i]: 右辺がiになる組み合わせの数

int main(void){
    int n, d;
    cin >> n >> d;
    vector<int> wzd(n * n);
    for(int w = 1; w <= n; ++w){
        for(int z = 1; z <= n; ++z){
            int right = w * w - z * z + d;
            if(right >= 2 && right <= 2 * n * n) ++WZ[right];
        }
    }
    int ans = 0;
    for(int x = 1; x <= n; ++x){
        for(int y = 1; y <= n; ++y){
            int left = x * x + y * y;
            ++XY[left];
        }
    }
    for(int i = 2; i <= 2 * n * n; ++i){
        ans += XY[i] * WZ[i];
    }
    cout << ans << endl;
}
0