結果

問題 No.800 四平方定理
ユーザー 259_Momone259_Momone
提出日時 2019-03-17 21:37:55
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 688 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 1,155 ms
使用メモリ 65,808 KB
最終ジャッジ日時 2023-02-11 04:59:01
合計ジャッジ時間 12,304 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 7 ms
6,948 KB
testcase_01 AC 13 ms
4,904 KB
testcase_02 AC 9 ms
4,900 KB
testcase_03 AC 10 ms
6,948 KB
testcase_04 AC 8 ms
4,900 KB
testcase_05 AC 9 ms
6,948 KB
testcase_06 AC 15 ms
4,904 KB
testcase_07 AC 12 ms
4,904 KB
testcase_08 AC 15 ms
6,948 KB
testcase_09 AC 12 ms
4,900 KB
testcase_10 AC 322 ms
34,040 KB
testcase_11 AC 381 ms
52,696 KB
testcase_12 AC 374 ms
52,948 KB
testcase_13 AC 338 ms
35,508 KB
testcase_14 AC 381 ms
53,672 KB
testcase_15 AC 379 ms
52,616 KB
testcase_16 AC 382 ms
54,160 KB
testcase_17 AC 386 ms
52,404 KB
testcase_18 AC 386 ms
53,412 KB
testcase_19 AC 384 ms
53,480 KB
testcase_20 AC 1 ms
6,952 KB
testcase_21 AC 2 ms
4,908 KB
testcase_22 AC 388 ms
52,360 KB
testcase_23 AC 688 ms
65,808 KB
testcase_24 AC 681 ms
65,612 KB
testcase_25 AC 686 ms
65,572 KB
testcase_26 AC 1 ms
4,904 KB
testcase_27 AC 1 ms
4,904 KB
testcase_28 AC 675 ms
65,448 KB
testcase_29 AC 681 ms
65,708 KB
testcase_30 AC 681 ms
65,456 KB
testcase_31 AC 633 ms
61,128 KB
testcase_32 AC 683 ms
65,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
    long N, D;
    cin >> N >> D;

    vector<long> p, n;

    for(long i = 1; i <= N; ++i){
        for(long j = 1; j <= N; ++j){
            p.push_back(i * i + j * j);
            n.push_back(i * i - j * j);
        }
    }
    n.push_back(-1000000000);
    sort(p.begin(), p.end());
    sort(n.rbegin(), n.rend());

    auto it = n.begin(), it2 = n.begin(), en = n.end();

    long ans(0), prv(-1);
    for(auto i : p){
        if(i != prv){
            prv = i;
            while(it != en && *it + i > D)++it;
            while(it2 != en && *it2 + i >= D)++it2;
        }
        ans += it2 - it;
    }
    cout << ans << endl;

    return 0;
}
0