結果

問題 No.800 四平方定理
ユーザー finefine
提出日時 2019-03-17 22:39:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 169,652 KB
実行使用メモリ 44,952 KB
最終ジャッジ日時 2023-09-22 08:37:49
合計ジャッジ時間 9,454 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 250 ms
23,960 KB
testcase_11 AC 267 ms
25,856 KB
testcase_12 AC 279 ms
27,664 KB
testcase_13 AC 227 ms
19,196 KB
testcase_14 AC 247 ms
25,944 KB
testcase_15 AC 281 ms
28,500 KB
testcase_16 AC 250 ms
26,032 KB
testcase_17 AC 250 ms
26,660 KB
testcase_18 AC 304 ms
28,044 KB
testcase_19 AC 304 ms
29,284 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 308 ms
27,928 KB
testcase_23 AC 517 ms
43,704 KB
testcase_24 AC 444 ms
34,944 KB
testcase_25 AC 518 ms
44,484 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 440 ms
34,724 KB
testcase_29 AC 480 ms
43,784 KB
testcase_30 AC 444 ms
34,632 KB
testcase_31 AC 412 ms
33,764 KB
testcase_32 AC 458 ms
44,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    vector<int> v1;
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            v1.push_back(x * x + y * y);
        }
    }
    sort(v1.begin(), v1.end());

    vector<int> v2;
    for (int w = 1; w <= n; w++) {
        int lim = min(n * n, w * w + d);
        for (int z = 1; z * z <= lim; z++) {
            v2.push_back(d + w * w - z * z);
        }
    }
    sort(v2.begin(), v2.end());

    int i = 0, j = 0;
    ll ans = 0;
    while (i < v1.size() && j < v2.size()) {
        while (i < v1.size() && j < v2.size()) {
            if (v1[i] == v2[j]) break;
            if (v1[i] < v2[j]) i++;
            else j++;
        }

        int ii = i, jj = j;
        while (i < v1.size()) {
            if (v1[i] != v1[ii]) break;
            i++;
        }

        while (j < v2.size()) {
            if (v2[j] != v2[jj]) break;
            j++;
        }

        ll tmp = i - ii;
        tmp *= j - jj;
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}
0