結果

問題 No.800 四平方定理
ユーザー fine
提出日時 2019-03-17 21:36:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 605 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 172,676 KB
実行使用メモリ 34,176 KB
最終ジャッジ日時 2024-07-07 21:02:13
合計ジャッジ時間 26,981 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 TLE * 5 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    map<int, int> m;
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            int val = x * x + y * y;
            m[val]++;
        }
    }
    
    ll ans = 0;
    for (int z = 1; z <= n; z++) {
        for (int w = 1; w <= n; w++) {
            int val = d + w * w - z * z;
            if (m.find(val) == m.end()) continue;
            ans += m[val];
        }
    }
    cout << ans << endl;
    return 0;
}
0