結果

問題 No.800 四平方定理
ユーザー lightninglightning
提出日時 2019-03-17 22:25:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,328 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 1,501 ms
コンパイル使用メモリ 172,616 KB
実行使用メモリ 50,012 KB
最終ジャッジ日時 2023-09-22 07:49:36
合計ジャッジ時間 20,481 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 11 ms
4,472 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 11 ms
4,388 KB
testcase_09 AC 10 ms
4,380 KB
testcase_10 AC 540 ms
26,700 KB
testcase_11 AC 650 ms
29,068 KB
testcase_12 AC 628 ms
28,524 KB
testcase_13 AC 571 ms
27,688 KB
testcase_14 AC 635 ms
28,948 KB
testcase_15 AC 636 ms
28,748 KB
testcase_16 AC 614 ms
29,136 KB
testcase_17 AC 639 ms
29,344 KB
testcase_18 AC 655 ms
28,884 KB
testcase_19 AC 645 ms
29,008 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 639 ms
29,468 KB
testcase_23 AC 1,308 ms
49,872 KB
testcase_24 AC 1,313 ms
50,012 KB
testcase_25 AC 1,328 ms
49,864 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1,309 ms
49,860 KB
testcase_29 AC 1,313 ms
49,872 KB
testcase_30 AC 1,304 ms
50,008 KB
testcase_31 AC 1,183 ms
47,556 KB
testcase_32 AC 1,300 ms
49,864 KB
権限があれば一括ダウンロードができます

ソースコード

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;
unordered_map<int,int> mp;

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

0