結果

問題 No.800 四平方定理
ユーザー nebukuro09nebukuro09
提出日時 2019-04-18 05:18:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 166,732 KB
実行使用メモリ 66,080 KB
最終ジャッジ日時 2023-10-22 07:40:10
合計ジャッジ時間 3,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,680 KB
testcase_01 AC 3 ms
7,680 KB
testcase_02 AC 3 ms
7,680 KB
testcase_03 AC 3 ms
7,680 KB
testcase_04 AC 3 ms
7,680 KB
testcase_05 AC 3 ms
7,680 KB
testcase_06 AC 3 ms
7,680 KB
testcase_07 AC 3 ms
7,680 KB
testcase_08 AC 3 ms
7,624 KB
testcase_09 AC 3 ms
7,680 KB
testcase_10 AC 44 ms
36,352 KB
testcase_11 AC 49 ms
40,448 KB
testcase_12 AC 50 ms
40,448 KB
testcase_13 AC 44 ms
36,352 KB
testcase_14 AC 51 ms
40,448 KB
testcase_15 AC 51 ms
40,448 KB
testcase_16 AC 49 ms
40,448 KB
testcase_17 AC 50 ms
40,448 KB
testcase_18 AC 53 ms
40,448 KB
testcase_19 AC 53 ms
40,448 KB
testcase_20 AC 2 ms
5,576 KB
testcase_21 AC 2 ms
5,576 KB
testcase_22 AC 52 ms
40,448 KB
testcase_23 AC 104 ms
66,080 KB
testcase_24 AC 96 ms
66,080 KB
testcase_25 AC 104 ms
65,900 KB
testcase_26 AC 2 ms
5,576 KB
testcase_27 AC 2 ms
5,576 KB
testcase_28 AC 97 ms
65,776 KB
testcase_29 AC 101 ms
65,964 KB
testcase_30 AC 96 ms
65,836 KB
testcase_31 AC 90 ms
65,024 KB
testcase_32 AC 100 ms
66,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;

const ll M = 2000 * 2000;
ll N, D;
ll cnt[M*2+1];

void solve() {
    cin >> N >> D;

    ll ans = 0;
    REP2 (z, 1, N+1) REP2 (w, 1, N+1) cnt[z*z-w*w+M] += 1;
    REP2 (x, 1, N+1) REP2 (y, 1, N+1) {
        if (D - x*x - y*y < -M) continue;
        if (D - x*x - y*y >  M) continue;
        ans += cnt[D-x*x-y*y+M];
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0