結果

問題 No.781 円周上の格子点の数え上げ
ユーザー simansiman
提出日時 2021-07-01 20:32:52
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 103,512 KB
実行使用メモリ 42,664 KB
最終ジャッジ日時 2023-09-10 18:41:47
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 23 ms
42,608 KB
testcase_09 AC 23 ms
42,588 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 67 ms
42,600 KB
testcase_13 AC 117 ms
42,664 KB
testcase_14 AC 3 ms
7,732 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 57 ms
28,348 KB
testcase_18 AC 14 ms
26,640 KB
testcase_19 AC 14 ms
27,644 KB
testcase_20 AC 15 ms
27,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_V = 10010000;
int counter[MAX_V];

int main() {
  int X, Y;
  cin >> X >> Y;
  int S, L;
  S = ceil(sqrt(X));

  if (X == Y) {
    L = S;
  } else {
    L = ceil(sqrt(Y));
  }

  assert(MAX_V > L * L);
  for (int x = 0; x <= L * L; ++x) {
    counter[x] = 0;
  }

  for (int x = S; x <= L; ++x) {
    int v = x * x;
    if (v < X) continue;
    if (v > Y) continue;

    counter[v] += 1;
  }

  for (int y = 0; y < L; ++y) {
    int dy = y * y;
    for (int x = 0; x < L; ++x) {
      int dx = x * x;
      int v = dy + dx;

      if (v < X) continue;
      if (v > Y) continue;

      counter[v] += 1;
    }
  }

  int ans = 0;

  for (int x = 0; x <= L * L; ++x) {
    int value = counter[x];
    ans = max(ans, value);
  }

  cout << 4 * ans << endl;

  return 0;
}
0