結果

問題 No.800 四平方定理
ユーザー 0w10w1
提出日時 2020-11-16 16:10:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 204,748 KB
実行使用メモリ 50,464 KB
最終ジャッジ日時 2023-09-30 07:18:52
合計ジャッジ時間 8,170 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
34,624 KB
testcase_01 AC 16 ms
34,688 KB
testcase_02 AC 16 ms
34,640 KB
testcase_03 AC 16 ms
34,752 KB
testcase_04 AC 15 ms
34,828 KB
testcase_05 AC 17 ms
34,568 KB
testcase_06 AC 18 ms
34,780 KB
testcase_07 AC 16 ms
34,752 KB
testcase_08 AC 18 ms
34,760 KB
testcase_09 AC 17 ms
34,884 KB
testcase_10 AC 145 ms
42,280 KB
testcase_11 AC 164 ms
44,360 KB
testcase_12 AC 165 ms
43,308 KB
testcase_13 AC 153 ms
42,604 KB
testcase_14 AC 167 ms
43,560 KB
testcase_15 AC 170 ms
43,168 KB
testcase_16 AC 170 ms
43,988 KB
testcase_17 AC 160 ms
44,484 KB
testcase_18 AC 169 ms
43,244 KB
testcase_19 AC 168 ms
43,772 KB
testcase_20 AC 15 ms
34,240 KB
testcase_21 AC 14 ms
34,248 KB
testcase_22 AC 166 ms
43,464 KB
testcase_23 AC 285 ms
50,464 KB
testcase_24 AC 289 ms
49,968 KB
testcase_25 AC 298 ms
50,456 KB
testcase_26 AC 15 ms
34,420 KB
testcase_27 AC 14 ms
34,204 KB
testcase_28 AC 275 ms
50,004 KB
testcase_29 AC 277 ms
50,012 KB
testcase_30 AC 280 ms
50,156 KB
testcase_31 AC 268 ms
49,116 KB
testcase_32 AC 291 ms
50,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  ios::sync_with_stdio(false);

  int N, D; { cin >> N >> D; }

  vector<int> s; {
    for (int x = 1; x <= N; ++x) {
      for (int y = 1; y <= N; ++y) {
        s.push_back(x * x + y * y);
      }
    }
    sort(s.begin(), s.end());
  }

  vector<int> pc(2000 * 2000 * 2 + 1); {
    for (int v : s) pc[v] += 1;
    for (int i = 1; i < pc.size(); ++i) pc[i] += pc[i - 1];
  }

  int64_t res = 0; {
    for (int w = 1; w <= N; ++w) {
      for (int z = 1; z <= N; ++z) {
        int t = w * w - z * z + D;
        if (t <= 0 || pc.size() <= t) continue;
        res += pc[t] - pc[t - 1];
      }
    }
  }

  cout << res << endl;
}

0