結果

問題 No.800 四平方定理
ユーザー yumarimoyumarimo
提出日時 2019-04-07 01:37:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,467 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 171,428 KB
実行使用メモリ 37,524 KB
最終ジャッジ日時 2023-09-07 18:45:14
合計ジャッジ時間 20,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,376 KB
testcase_01 AC 16 ms
4,376 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 12 ms
4,376 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 653 ms
20,132 KB
testcase_11 AC 674 ms
36,416 KB
testcase_12 AC 733 ms
37,224 KB
testcase_13 AC 544 ms
20,248 KB
testcase_14 AC 600 ms
37,524 KB
testcase_15 AC 731 ms
36,884 KB
testcase_16 AC 602 ms
37,408 KB
testcase_17 AC 600 ms
36,852 KB
testcase_18 AC 813 ms
36,596 KB
testcase_19 AC 827 ms
36,188 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 818 ms
36,912 KB
testcase_23 AC 1,467 ms
35,816 KB
testcase_24 AC 1,163 ms
36,868 KB
testcase_25 AC 1,418 ms
36,588 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1,134 ms
36,084 KB
testcase_29 AC 1,305 ms
36,284 KB
testcase_30 AC 1,128 ms
36,276 KB
testcase_31 AC 1,022 ms
36,488 KB
testcase_32 AC 1,174 ms
37,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, d;
    cin >> n >> d;

    vector<llong> XY;
    for (llong x = 1; x <= n; ++x) {
        for (llong y = 1; y <= n; ++y) {
            XY.push_back(x * x + y * y);
        }
    }

    sort(all(XY));

    llong res = 0;
    for (llong z = 1; z <= n; ++z) {
        for (llong w = 1; w <= n; ++w) {
            llong target = w * w - z * z + d;
            res += upper_bound(all(XY), target) - lower_bound(all(XY), target);
        }
    }

    cout << res << endl;

    return 0;
}
0