結果

問題 No.1593 Perfect Distance
コンテスト
ユーザー ikashoppin
提出日時 2021-07-09 21:36:26
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 796 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,518 ms
コンパイル使用メモリ 214,668 KB
実行使用メモリ 22,580 KB
最終ジャッジ日時 2026-06-21 14:29:52
合計ジャッジ時間 2,420 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>
ostream &operator<<(ostream &os, const vector<T> &x){
    os << "{";
    for(size_t i = 0; i < x.size(); i++){
        if(i < x.size()-1) os << x[i] << ", ";
        else os << x[i];
    }
    os << "}";
    return os;
}

int main(void){
    lli n;
    cin >> n;
    n*=n;
    unordered_map<lli, bool> f;
    for(lli y = 1; y*y <= n; y++){
        f[y*y] = true;
    }
    lli ans = 0;
    for(lli x = 1; x*x <= n; x++){
        if(f[n-x*x]) ans++;
    }
    cout << ans << endl;
    return 0;
}
0