結果

問題 No.800 四平方定理
ユーザー sykwersykwer
提出日時 2019-03-17 21:30:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 843 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 115,080 KB
実行使用メモリ 85,568 KB
最終ジャッジ日時 2023-09-22 03:58:29
合計ジャッジ時間 13,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,376 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 12 ms
4,376 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 17 ms
4,624 KB
testcase_07 AC 15 ms
5,048 KB
testcase_08 AC 17 ms
5,468 KB
testcase_09 AC 15 ms
4,676 KB
testcase_10 AC 407 ms
43,720 KB
testcase_11 AC 443 ms
48,944 KB
testcase_12 AC 459 ms
50,756 KB
testcase_13 AC 381 ms
35,508 KB
testcase_14 AC 415 ms
46,796 KB
testcase_15 AC 459 ms
50,216 KB
testcase_16 AC 419 ms
46,108 KB
testcase_17 AC 434 ms
46,348 KB
testcase_18 AC 492 ms
52,840 KB
testcase_19 AC 493 ms
53,636 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 499 ms
53,324 KB
testcase_23 AC 843 ms
85,568 KB
testcase_24 AC 740 ms
66,976 KB
testcase_25 AC 839 ms
84,184 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 742 ms
67,072 KB
testcase_29 AC 804 ms
83,992 KB
testcase_30 AC 746 ms
66,556 KB
testcase_31 AC 691 ms
65,240 KB
testcase_32 AC 765 ms
83,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, D;
    cin >> N >> D;

    vector<int> pool1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            pool1.push_back(i * i + j * j);
        }
    }
    sort(pool1.begin(), pool1.end());

    vector<int> pool2;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            int val = i * i - j * j + D;
            if (val <= 0) continue;
            pool2.push_back(val);
        }
    }
    sort(pool2.begin(), pool2.end());

    int ret = 0;
    for (int val : pool1) {
        ret += upper_bound(pool2.begin(), pool2.end(), val) - lower_bound(pool2.begin(), pool2.end(), val);
    }

    cout << ret << endl;

    return 0;
}
0