結果

問題 No.800 四平方定理
ユーザー ttttanttttan
提出日時 2019-03-17 22:01:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 771 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 180,048 KB
実行使用メモリ 123,340 KB
最終ジャッジ日時 2023-09-22 06:07:56
合計ジャッジ時間 20,821 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 17 ms
5,164 KB
testcase_02 AC 12 ms
4,648 KB
testcase_03 AC 13 ms
4,584 KB
testcase_04 AC 14 ms
4,648 KB
testcase_05 AC 15 ms
4,764 KB
testcase_06 AC 19 ms
5,156 KB
testcase_07 AC 26 ms
6,280 KB
testcase_08 AC 33 ms
7,256 KB
testcase_09 AC 17 ms
4,868 KB
testcase_10 AC 1,099 ms
62,392 KB
testcase_11 AC 1,050 ms
61,836 KB
testcase_12 AC 1,267 ms
69,408 KB
testcase_13 AC 785 ms
47,840 KB
testcase_14 AC 833 ms
53,180 KB
testcase_15 AC 1,239 ms
68,944 KB
testcase_16 AC 834 ms
53,584 KB
testcase_17 AC 846 ms
53,824 KB
testcase_18 AC 1,504 ms
81,636 KB
testcase_19 AC 1,482 ms
81,616 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1,527 ms
80,932 KB
testcase_23 TLE -
testcase_24 AC 1,718 ms
88,736 KB
testcase_25 TLE -
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1,670 ms
88,388 KB
testcase_29 TLE -
testcase_30 AC 1,670 ms
88,368 KB
testcase_31 AC 1,626 ms
84,044 KB
testcase_32 AC 1,923 ms
100,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,d;cin>>n>>d;
    map<ll,ll> mp;
    vector<ll> v;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
          if(i*i+d-j*j>0){
            mp[i*i+d-j*j]++;
            v.push_back(i*i+d-j*j);
          }
        }
    }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  ll r=v.size();
  ll cnt[r];
  for(ll i=0;i<r;i++){
    cnt[i]=mp[v[i]];
  }
    ll ans=0;
    for(ll i=1;i<n;i++){
        for(ll j=i+1;j<=n;j++){
          ll y=lower_bound(v.begin(),v.end(),i*i+j*j)-v.begin();
          if(v[y]==i*i+j*j){
            ans+=cnt[y];
          }
        }
    }
    ll anss=0;
  for(ll i=1;i<=n;i++)anss+=mp[i*i+i*i];
  
    cout<<ans*2+anss<<endl;
}
0