結果

問題 No.800 四平方定理
ユーザー Y17Y17
提出日時 2019-03-17 22:21:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,422 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 151,692 KB
実行使用メモリ 89,492 KB
最終ジャッジ日時 2023-09-22 07:34:33
合計ジャッジ時間 18,648 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 9 ms
4,652 KB
testcase_02 AC 7 ms
4,436 KB
testcase_03 AC 7 ms
4,384 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 8 ms
4,392 KB
testcase_06 AC 11 ms
5,528 KB
testcase_07 AC 10 ms
4,844 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 8 ms
4,476 KB
testcase_10 AC 555 ms
46,108 KB
testcase_11 AC 586 ms
48,012 KB
testcase_12 AC 626 ms
51,248 KB
testcase_13 AC 436 ms
42,064 KB
testcase_14 AC 525 ms
44,260 KB
testcase_15 AC 672 ms
50,320 KB
testcase_16 AC 493 ms
44,324 KB
testcase_17 AC 480 ms
42,612 KB
testcase_18 AC 757 ms
57,272 KB
testcase_19 AC 785 ms
58,120 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 749 ms
55,284 KB
testcase_23 AC 1,398 ms
89,492 KB
testcase_24 AC 1,095 ms
82,800 KB
testcase_25 AC 1,422 ms
87,716 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1,092 ms
82,452 KB
testcase_29 AC 1,284 ms
86,772 KB
testcase_30 AC 1,063 ms
82,452 KB
testcase_31 AC 1,037 ms
82,584 KB
testcase_32 AC 1,143 ms
82,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n, d;
    cin >> n >> d;

    long long ans = 0;
    unordered_map<long long, long long> mp;

  	long long mi = LLONG_MAX;
  	long long ma = 0;
    for(long long i = 1;i <= n;i++){
        for(long long j = 1;j <= n;j++){
            if(i*i-j*j+d > 0 && i*i-j*j+d <= n*n+n*n){
                mp[i*i-j*j+d]++;
              	ma = max(ma, i*i-j*j+d);
              	mi = min(mi, i*i-j*j+d);
            }
        }
    }

    for(long long i = 1;i <= n;i++){
        for(long long j = 1;j <= n;j++){
          	if(i*i+j*j < mi) continue;
          	if(i*i+j*j > ma) break;
            ans += mp[i*i+j*j];
        }
    }


    cout << ans << endl;

    return 0;
}


0