結果

問題 No.800 四平方定理
ユーザー tottoripapertottoripaper
提出日時 2019-03-18 18:19:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 669 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 4,401 ms
コンパイル使用メモリ 170,424 KB
実行使用メモリ 34,788 KB
最終ジャッジ日時 2023-09-25 16:40:59
合計ジャッジ時間 12,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,380 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 319 ms
18,692 KB
testcase_11 AC 365 ms
29,676 KB
testcase_12 AC 357 ms
28,668 KB
testcase_13 AC 333 ms
19,300 KB
testcase_14 AC 362 ms
30,036 KB
testcase_15 AC 361 ms
29,120 KB
testcase_16 AC 366 ms
30,244 KB
testcase_17 AC 368 ms
28,540 KB
testcase_18 AC 366 ms
29,892 KB
testcase_19 AC 366 ms
28,612 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 376 ms
30,152 KB
testcase_23 AC 669 ms
34,440 KB
testcase_24 AC 651 ms
34,444 KB
testcase_25 AC 660 ms
34,660 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 644 ms
34,336 KB
testcase_29 AC 653 ms
34,444 KB
testcase_30 AC 652 ms
34,788 KB
testcase_31 AC 602 ms
32,976 KB
testcase_32 AC 658 ms
34,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, D;
std::vector<int> v, w;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::cin >> N >> D;

    for(int i=1;i<=N;++i){
        for(int j=1;j<=N;++j){
            v.emplace_back(i * i + j * j);
            w.emplace_back(- i * i + j * j + D);
        }
    }

    std::sort(v.begin(), v.end());
    std::sort(w.begin(), w.end());

    ll cnt = 0;

    int i = 0, j = 0;
    for(int s : v){
        while(i < w.size() && w[i] < s){
            i += 1;
        }

        j = i;

        while(j < w.size() && w[j] <= s){
            j += 1;
        }

        if(i < w.size() && w[i] == s){
            cnt += j - i;
        }
    }

    std::cout << cnt << std::endl;
}
0