結果

問題 No.800 四平方定理
ユーザー lightninglightning
提出日時 2019-03-17 21:47:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,362 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 177,344 KB
実行使用メモリ 42,692 KB
最終ジャッジ日時 2023-09-22 04:58:32
合計ジャッジ時間 25,963 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,376 KB
testcase_01 AC 29 ms
4,476 KB
testcase_02 AC 21 ms
4,384 KB
testcase_03 AC 23 ms
4,376 KB
testcase_04 AC 19 ms
4,380 KB
testcase_05 AC 23 ms
4,376 KB
testcase_06 AC 34 ms
4,736 KB
testcase_07 AC 28 ms
4,404 KB
testcase_08 AC 30 ms
4,864 KB
testcase_09 AC 30 ms
4,608 KB
testcase_10 AC 1,686 ms
38,224 KB
testcase_11 AC 1,705 ms
42,160 KB
testcase_12 AC 1,723 ms
41,580 KB
testcase_13 AC 1,602 ms
39,480 KB
testcase_14 AC 1,603 ms
42,232 KB
testcase_15 AC 1,801 ms
41,856 KB
testcase_16 AC 1,648 ms
42,568 KB
testcase_17 AC 1,727 ms
42,428 KB
testcase_18 AC 1,947 ms
42,432 KB
testcase_19 AC 1,803 ms
42,476 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1,971 ms
42,692 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n,d;
vector<int> e;
map<int,int> mp;
int binary_search(int x){
    auto itr = lower_bound(all(e), x);
    if(x==*itr)return mp[x];
    else return 0;
}

int main(){
    cin >> n >> d;
    vector<int> a(n);
    vector<int> b(n);
    REP(i,n){
        a[i]=b[i]=i+1;
    }
    e.resize(n*n);
    REP(i,n){
        REP(j,n){
            int c = a[i]*a[i]+b[j]*b[j];
            e[i*n+j] = c;
            auto itr = mp.find(c);
            if(itr!=mp.end()){
                mp[c]++;
            }else{
                mp[c]=1;
            }
            
        }
    }
    SORT(e);
    ll res = 0;
    REP(i,n){
        REP(j,n){
            int x = d+(i+1)*(i+1)-(j+1)*(j+1);
            res+=binary_search(x);
        }
    }
    put(res);
    return 0;
}

0