結果

問題 No.800 四平方定理
ユーザー 259_Momone259_Momone
提出日時 2019-03-17 21:37:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 708 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 153,508 KB
実行使用メモリ 67,544 KB
最終ジャッジ日時 2023-09-22 04:22:38
合計ジャッジ時間 13,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 14 ms
4,560 KB
testcase_02 AC 10 ms
4,376 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 15 ms
4,572 KB
testcase_07 AC 12 ms
4,616 KB
testcase_08 AC 15 ms
4,616 KB
testcase_09 AC 14 ms
4,556 KB
testcase_10 AC 345 ms
34,072 KB
testcase_11 AC 406 ms
54,300 KB
testcase_12 AC 392 ms
54,708 KB
testcase_13 AC 357 ms
35,548 KB
testcase_14 AC 393 ms
53,808 KB
testcase_15 AC 395 ms
53,644 KB
testcase_16 AC 399 ms
54,060 KB
testcase_17 AC 400 ms
53,756 KB
testcase_18 AC 402 ms
54,204 KB
testcase_19 AC 397 ms
54,260 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 401 ms
54,344 KB
testcase_23 AC 708 ms
66,692 KB
testcase_24 AC 699 ms
66,280 KB
testcase_25 AC 705 ms
66,276 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 693 ms
67,544 KB
testcase_29 AC 697 ms
66,320 KB
testcase_30 AC 700 ms
66,336 KB
testcase_31 AC 653 ms
62,916 KB
testcase_32 AC 701 ms
66,840 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