結果

問題 No.800 四平方定理
ユーザー ei1333333ei1333333
提出日時 2019-03-17 21:29:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 199,392 KB
実行使用メモリ 23,108 KB
最終ジャッジ日時 2023-09-22 03:51:32
合計ジャッジ時間 3,716 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
22,868 KB
testcase_01 AC 7 ms
23,056 KB
testcase_02 AC 7 ms
22,860 KB
testcase_03 AC 7 ms
23,108 KB
testcase_04 AC 7 ms
22,856 KB
testcase_05 AC 9 ms
23,052 KB
testcase_06 AC 7 ms
22,868 KB
testcase_07 AC 8 ms
23,028 KB
testcase_08 AC 7 ms
22,860 KB
testcase_09 AC 8 ms
22,884 KB
testcase_10 AC 21 ms
22,976 KB
testcase_11 AC 20 ms
22,868 KB
testcase_12 AC 22 ms
23,056 KB
testcase_13 AC 19 ms
22,876 KB
testcase_14 AC 20 ms
22,892 KB
testcase_15 AC 19 ms
22,856 KB
testcase_16 AC 22 ms
22,956 KB
testcase_17 AC 20 ms
22,884 KB
testcase_18 AC 23 ms
22,856 KB
testcase_19 AC 25 ms
22,856 KB
testcase_20 AC 7 ms
22,884 KB
testcase_21 AC 8 ms
22,884 KB
testcase_22 AC 27 ms
22,972 KB
testcase_23 AC 40 ms
22,884 KB
testcase_24 AC 37 ms
22,888 KB
testcase_25 AC 42 ms
22,876 KB
testcase_26 AC 7 ms
22,868 KB
testcase_27 AC 6 ms
22,956 KB
testcase_28 AC 40 ms
22,908 KB
testcase_29 AC 42 ms
22,884 KB
testcase_30 AC 39 ms
22,896 KB
testcase_31 AC 37 ms
22,864 KB
testcase_32 AC 37 ms
22,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, D;
  int uku = 2000 * 2001 + (int) (1e6);
  int sq[2000 * 2001 + (int) (1e6)] = {};


  cin >> N >> D;
  int ret = 0;
  for(int y = 1; y * y < uku && y <= N; y++) {
    for(int z = 1; z * z + y * y < uku && z <= N; z++) {
      sq[y * y + z * z]++;
    }
  }

  for(int w = 1; w <= N; w++) {
    int M = w * w + D;
    for(int x = 1; x * x <= M && x <= N; x++) {
      ret += sq[M - x * x];
      /*
      for(int y = 1; x * x + y * y <= M && y <= N; y++) {
        int sa = M - x * x - y * y;
        ret += sq[sa];
      }
       */
    }
  }
  cout << ret << endl;
}







0