結果

問題 No.800 四平方定理
ユーザー revkiru
提出日時 2024-10-04 16:01:31
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,075 bytes
コンパイル時間 6,099 ms
コンパイル使用メモリ 281,224 KB
実行使用メモリ 814,232 KB
最終ジャッジ日時 2024-10-04 16:01:41
合計ジャッジ時間 8,817 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

constexpr int N = 1e6 + 7;

int n, k;
i64 cnt[N << 8];
std::vector<i64> vec;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    // freopen("alive.in", "r", stdin);
    // freopen("alive.out", "w", stdout);

    std::cin >> n >> k;
    memset(cnt, -1, sizeof(cnt));
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            i64 z = 1ll * x * x - 1ll * y * y + k;
            vec.push_back(z);
        }
    }
    std::sort(vec.begin(), vec.end());

    i64 ans = 0;
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= n; y++) {
            i64 z = x * x + y * y;
            if (cnt[z] != -1)
                ans += cnt[z];
            else {
                auto it0 = std::lower_bound(vec.begin(), vec.end(), z);
                auto it1 = std::upper_bound(vec.begin(), vec.end(), z);
                i64 d = it1 - it0;
                ans += d;
                cnt[z] = d;
            }
        }
    }

    std::cout << ans << "\n";
    return 0;
}
0