結果

問題 No.800 四平方定理
ユーザー _____TAB__________TAB_____
提出日時 2019-03-17 22:02:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 68,888 KB
実行使用メモリ 38,352 KB
最終ジャッジ日時 2023-09-22 06:10:49
合計ジャッジ時間 2,724 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
38,012 KB
testcase_01 AC 11 ms
38,004 KB
testcase_02 AC 11 ms
38,008 KB
testcase_03 AC 11 ms
38,188 KB
testcase_04 AC 11 ms
38,008 KB
testcase_05 AC 12 ms
37,976 KB
testcase_06 AC 12 ms
37,884 KB
testcase_07 AC 11 ms
38,000 KB
testcase_08 AC 11 ms
37,868 KB
testcase_09 AC 12 ms
38,032 KB
testcase_10 AC 30 ms
38,100 KB
testcase_11 AC 35 ms
37,976 KB
testcase_12 AC 34 ms
38,020 KB
testcase_13 AC 33 ms
37,924 KB
testcase_14 AC 34 ms
38,096 KB
testcase_15 AC 34 ms
38,040 KB
testcase_16 AC 34 ms
38,156 KB
testcase_17 AC 35 ms
38,160 KB
testcase_18 AC 34 ms
37,924 KB
testcase_19 AC 33 ms
37,996 KB
testcase_20 AC 11 ms
37,896 KB
testcase_21 AC 11 ms
38,176 KB
testcase_22 AC 33 ms
38,352 KB
testcase_23 AC 67 ms
37,996 KB
testcase_24 AC 63 ms
38,036 KB
testcase_25 AC 67 ms
37,996 KB
testcase_26 AC 12 ms
38,036 KB
testcase_27 AC 11 ms
37,880 KB
testcase_28 AC 63 ms
38,156 KB
testcase_29 AC 65 ms
38,020 KB
testcase_30 AC 65 ms
37,892 KB
testcase_31 AC 59 ms
38,164 KB
testcase_32 AC 65 ms
38,020 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