結果

問題 No.800 四平方定理
ユーザー suzuken_wsuzuken_w
提出日時 2020-03-16 17:38:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,383 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 181,536 KB
実行使用メモリ 68,340 KB
最終ジャッジ日時 2023-08-18 19:22:19
合計ジャッジ時間 20,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,380 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 11 ms
4,380 KB
testcase_03 AC 11 ms
4,376 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 18 ms
4,736 KB
testcase_08 AC 12 ms
4,880 KB
testcase_09 AC 15 ms
4,380 KB
testcase_10 AC 599 ms
35,220 KB
testcase_11 AC 606 ms
38,112 KB
testcase_12 AC 678 ms
37,728 KB
testcase_13 AC 457 ms
28,108 KB
testcase_14 AC 495 ms
37,392 KB
testcase_15 AC 671 ms
38,196 KB
testcase_16 AC 503 ms
38,408 KB
testcase_17 AC 507 ms
38,528 KB
testcase_18 AC 805 ms
37,124 KB
testcase_19 AC 813 ms
37,240 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 807 ms
38,064 KB
testcase_23 AC 1,383 ms
68,340 KB
testcase_24 AC 976 ms
51,572 KB
testcase_25 AC 1,369 ms
67,600 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 986 ms
50,868 KB
testcase_29 AC 1,207 ms
67,588 KB
testcase_30 AC 979 ms
51,068 KB
testcase_31 AC 916 ms
48,560 KB
testcase_32 AC 1,064 ms
67,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
constexpr ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,d;
    cin>>n>>d;
    V<ll> a(n);
    for(ll i=0;i<n;i++){
        a[i]=(i+1)*(i+1);
    }
    V<ll> dat(n*n);
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            dat[cnt++]=a[i]+a[j];
           // cout<<dat[cnt-1]<<endl;
        }
    }
    V<ll> dat2;
    cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]-a[j]+d>=2ll){
                dat2.emplace_back(a[i]-a[j]+d);
             //   cout<<dat2[cnt++]<<endl;
            }
        }
    }
    int m=dat2.size();
    sort(all(dat));
    ll ans=0;
   // cout<<m<<endl;
    for(int i=0;i<m;i++){
        ans+=upper_bound(all(dat),dat2[i])-lower_bound(all(dat),dat2[i]);
    }
    cout<<ans<<"\n";
}
0