結果

問題 No.800 四平方定理
ユーザー lightninglightning
提出日時 2019-03-17 22:32:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,405 ms / 2,000 ms
コード長 1,819 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 171,412 KB
実行使用メモリ 50,228 KB
最終ジャッジ日時 2023-09-22 08:16:06
合計ジャッジ時間 20,984 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 6 ms
4,384 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 10 ms
4,532 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 10 ms
4,416 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 590 ms
26,556 KB
testcase_11 AC 645 ms
28,916 KB
testcase_12 AC 653 ms
28,300 KB
testcase_13 AC 631 ms
27,676 KB
testcase_14 AC 706 ms
29,064 KB
testcase_15 AC 633 ms
28,560 KB
testcase_16 AC 688 ms
29,272 KB
testcase_17 AC 672 ms
29,260 KB
testcase_18 AC 698 ms
29,160 KB
testcase_19 AC 673 ms
28,876 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 694 ms
29,144 KB
testcase_23 AC 1,343 ms
49,996 KB
testcase_24 AC 1,296 ms
49,996 KB
testcase_25 AC 1,332 ms
50,228 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1,397 ms
49,992 KB
testcase_29 AC 1,356 ms
50,020 KB
testcase_30 AC 1,385 ms
49,820 KB
testcase_31 AC 1,254 ms
47,488 KB
testcase_32 AC 1,405 ms
49,908 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;
             }*/
        }
    }
    int 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