結果

問題 No.800 四平方定理
ユーザー sykwersykwer
提出日時 2019-03-17 21:30:18
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 899 ms
使用メモリ 84,324 KB
最終ジャッジ日時 2023-02-11 04:27:49
合計ジャッジ時間 13,183 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 8 ms
4,900 KB
testcase_01 AC 14 ms
4,904 KB
testcase_02 AC 10 ms
4,900 KB
testcase_03 AC 11 ms
4,908 KB
testcase_04 AC 11 ms
4,900 KB
testcase_05 AC 11 ms
4,904 KB
testcase_06 AC 16 ms
6,948 KB
testcase_07 AC 14 ms
5,192 KB
testcase_08 AC 15 ms
5,452 KB
testcase_09 AC 14 ms
4,900 KB
testcase_10 AC 393 ms
43,832 KB
testcase_11 AC 425 ms
49,292 KB
testcase_12 AC 440 ms
50,668 KB
testcase_13 AC 370 ms
35,484 KB
testcase_14 AC 404 ms
47,600 KB
testcase_15 AC 441 ms
49,760 KB
testcase_16 AC 404 ms
47,112 KB
testcase_17 AC 408 ms
47,768 KB
testcase_18 AC 478 ms
53,296 KB
testcase_19 AC 478 ms
52,876 KB
testcase_20 AC 1 ms
4,904 KB
testcase_21 AC 1 ms
6,948 KB
testcase_22 AC 483 ms
52,228 KB
testcase_23 AC 819 ms
83,472 KB
testcase_24 AC 724 ms
66,900 KB
testcase_25 AC 820 ms
84,180 KB
testcase_26 AC 1 ms
4,900 KB
testcase_27 AC 1 ms
4,900 KB
testcase_28 AC 722 ms
66,136 KB
testcase_29 AC 785 ms
84,324 KB
testcase_30 AC 725 ms
66,512 KB
testcase_31 AC 670 ms
63,420 KB
testcase_32 AC 757 ms
83,504 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