結果

問題 No.800 四平方定理
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-13 19:46:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 910 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 86,636 KB
実行使用メモリ 101,424 KB
最終ジャッジ日時 2023-09-08 02:23:33
合計ジャッジ時間 7,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
9,952 KB
testcase_01 AC 36 ms
7,500 KB
testcase_02 AC 23 ms
6,160 KB
testcase_03 AC 28 ms
6,692 KB
testcase_04 AC 22 ms
6,064 KB
testcase_05 AC 25 ms
6,556 KB
testcase_06 AC 46 ms
8,192 KB
testcase_07 AC 34 ms
6,976 KB
testcase_08 AC 48 ms
8,448 KB
testcase_09 AC 38 ms
7,760 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>

using namespace std;
using ll = long long;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i)
#define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)

int main() {
  int N, D;
  ins(N, D);

  map<int, int> m, m2;
  m2[0] += N;
  rep(i, N) {
    ++m[2*(i+1)*(i+1)];
    rep(j, i+1, N) {
      m[(i+1)*(i+1)+(j+1)*(j+1)] += 2;
      ++m2[(i+1)*(i+1)-(j+1)*(j+1)];
      ++m2[(j+1)*(j+1)-(i+1)*(i+1)];
    }
  }
  ll ans = 0;
  if (m2.size() < m.size())
    for (const auto& [wz, count]:m2)
      ans += m[wz+D] * count;
  else
    for (const auto& [xy, count]:m)
      ans += m2[xy-D] * count;
  cout << ans << endl;

  return 0;
}
0