結果

問題 No.800 四平方定理
ユーザー granddaifukugranddaifuku
提出日時 2020-04-25 17:47:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 165,972 KB
実行使用メモリ 73,680 KB
最終ジャッジ日時 2023-08-07 07:29:46
合計ジャッジ時間 4,241 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
73,496 KB
testcase_01 AC 21 ms
73,324 KB
testcase_02 AC 21 ms
73,360 KB
testcase_03 AC 22 ms
73,680 KB
testcase_04 AC 20 ms
73,380 KB
testcase_05 AC 20 ms
73,448 KB
testcase_06 AC 22 ms
73,492 KB
testcase_07 AC 22 ms
73,516 KB
testcase_08 AC 22 ms
73,492 KB
testcase_09 AC 21 ms
73,304 KB
testcase_10 AC 39 ms
73,324 KB
testcase_11 AC 45 ms
73,380 KB
testcase_12 AC 45 ms
73,440 KB
testcase_13 AC 42 ms
73,380 KB
testcase_14 AC 44 ms
73,516 KB
testcase_15 AC 43 ms
73,612 KB
testcase_16 AC 47 ms
73,496 KB
testcase_17 AC 48 ms
73,432 KB
testcase_18 AC 45 ms
73,488 KB
testcase_19 AC 47 ms
73,428 KB
testcase_20 AC 20 ms
73,588 KB
testcase_21 AC 21 ms
73,364 KB
testcase_22 AC 44 ms
73,528 KB
testcase_23 AC 92 ms
73,432 KB
testcase_24 AC 94 ms
73,380 KB
testcase_25 AC 91 ms
73,424 KB
testcase_26 AC 21 ms
73,492 KB
testcase_27 AC 20 ms
73,392 KB
testcase_28 AC 95 ms
73,376 KB
testcase_29 AC 91 ms
73,464 KB
testcase_30 AC 90 ms
73,320 KB
testcase_31 AC 81 ms
73,432 KB
testcase_32 AC 90 ms
73,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int N = 9000001;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, d;
    cin >> n >> d;
    ll res = 0;
    vector<int> plus(N), minus(N);
    FOR (i, 1, n + 1) {
        FOR (j, 1, n + 1) {
            int x = i * i - j * j;
            if (x >= 0) {
                plus[x]++;
            } else {
                x = abs(x);
                minus[x]++;
            }
        }
    }
    FOR (i, 1, n + 1) {
        FOR (j, 1, n + 1) {
            int tmp = i * i + j * j;
            int rest = d - tmp;
            if (rest >= 0) {
                res += plus[rest];
            } else {
                rest = abs(rest);
                res += minus[rest];
            }
        }
    }
    cout << res << endl;
    
    return 0;
}

0