結果

問題 No.800 四平方定理
ユーザー _____TAB__________TAB_____
提出日時 2019-03-17 22:02:42
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 445 ms
使用メモリ 38,172 KB
最終ジャッジ日時 2023-02-11 06:59:44
合計ジャッジ時間 3,323 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 13 ms
38,108 KB
testcase_01 AC 14 ms
37,948 KB
testcase_02 AC 14 ms
38,120 KB
testcase_03 AC 13 ms
38,092 KB
testcase_04 AC 14 ms
38,052 KB
testcase_05 AC 13 ms
37,964 KB
testcase_06 AC 13 ms
37,960 KB
testcase_07 AC 13 ms
38,004 KB
testcase_08 AC 14 ms
38,072 KB
testcase_09 AC 13 ms
37,992 KB
testcase_10 AC 29 ms
38,160 KB
testcase_11 AC 32 ms
38,076 KB
testcase_12 AC 34 ms
38,096 KB
testcase_13 AC 32 ms
38,004 KB
testcase_14 AC 36 ms
38,172 KB
testcase_15 AC 35 ms
38,164 KB
testcase_16 AC 38 ms
38,004 KB
testcase_17 AC 35 ms
38,136 KB
testcase_18 AC 34 ms
38,164 KB
testcase_19 AC 34 ms
38,136 KB
testcase_20 AC 12 ms
38,000 KB
testcase_21 AC 12 ms
37,956 KB
testcase_22 AC 36 ms
38,000 KB
testcase_23 AC 68 ms
37,880 KB
testcase_24 AC 65 ms
38,000 KB
testcase_25 AC 69 ms
38,164 KB
testcase_26 AC 13 ms
37,908 KB
testcase_27 AC 13 ms
38,076 KB
testcase_28 AC 66 ms
37,872 KB
testcase_29 AC 66 ms
38,140 KB
testcase_30 AC 66 ms
37,960 KB
testcase_31 AC 63 ms
38,044 KB
testcase_32 AC 65 ms
37,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
vector<int> dp(9e6,0);

int main(){
  int N, D;
  cin >> N >> D;
  int ans = 0;
  int m = 4e6;
  for(int x = 1; x <= N; ++x){
    for(int w = 1; w <= N; ++w){
      ++dp[x*x-w*w+m];
    }
  }
  for(int y = 1; y <= N; ++y){
    for(int z = 1; z <= N; ++z){
      //if(y*y + z*z > D) break;
      int d = D - y*y - z*z;
      if(d+m >= (int)dp.size() or d+m < 0) continue;
      ans += dp.at(d+m);
    }
  }
  cout << ans << endl;
}
0