結果

問題 No.800 四平方定理
ユーザー CleyLCleyL
提出日時 2023-06-29 12:33:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 74,236 KB
実行使用メモリ 96,844 KB
最終ジャッジ日時 2023-09-20 07:59:14
合計ジャッジ時間 3,384 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 4 ms
4,832 KB
testcase_02 AC 3 ms
4,496 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,652 KB
testcase_06 AC 4 ms
5,224 KB
testcase_07 AC 4 ms
4,772 KB
testcase_08 AC 4 ms
5,156 KB
testcase_09 AC 4 ms
4,840 KB
testcase_10 AC 51 ms
49,404 KB
testcase_11 AC 57 ms
55,020 KB
testcase_12 AC 56 ms
54,280 KB
testcase_13 AC 54 ms
51,448 KB
testcase_14 AC 57 ms
55,392 KB
testcase_15 AC 59 ms
54,740 KB
testcase_16 AC 58 ms
55,924 KB
testcase_17 AC 58 ms
56,000 KB
testcase_18 AC 59 ms
55,484 KB
testcase_19 AC 60 ms
55,664 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 59 ms
55,852 KB
testcase_23 AC 104 ms
96,844 KB
testcase_24 AC 100 ms
96,796 KB
testcase_25 AC 104 ms
96,480 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 101 ms
96,284 KB
testcase_29 AC 102 ms
96,624 KB
testcase_30 AC 104 ms
96,480 KB
testcase_31 AC 95 ms
89,768 KB
testcase_32 AC 101 ms
96,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(){
  long long n,d;cin>>n>>d;
  vector<long long> A(n*n*2+1);
  vector<long long> B(n*n+1);
  for(int i = 1; n >= i; i++){
    for(int j = i; n >= j; j++){
      if(n*n-1+d >= i*i+j*j){
        A[i*i+j*j] += (i==j?1:2);
      }
      if(n*n+n*n+d >= j*j-i*i){
        B[j*j-i*i]++;
      }
    }
  }
  long long ans = 0;
  for(int i = 0; 2*n*n >= i; i++){
    if(abs(i-d) <= n*n)ans += A[i]*B[abs(i-d)];
  }
  cout << ans << endl;
}
0