結果

問題 No.800 四平方定理
ユーザー ttttanttttan
提出日時 2019-03-17 23:18:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 627 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 154,068 KB
実行使用メモリ 60,540 KB
最終ジャッジ日時 2023-09-22 10:41:53
合計ジャッジ時間 10,568 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 8 ms
4,384 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 10 ms
4,712 KB
testcase_08 AC 10 ms
4,952 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 286 ms
31,520 KB
testcase_11 AC 291 ms
30,996 KB
testcase_12 AC 323 ms
34,696 KB
testcase_13 AC 240 ms
23,620 KB
testcase_14 AC 252 ms
25,468 KB
testcase_15 AC 323 ms
34,380 KB
testcase_16 AC 257 ms
25,332 KB
testcase_17 AC 261 ms
25,860 KB
testcase_18 AC 363 ms
39,824 KB
testcase_19 AC 367 ms
40,948 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 370 ms
39,856 KB
testcase_23 AC 627 ms
60,540 KB
testcase_24 AC 479 ms
42,124 KB
testcase_25 AC 621 ms
60,216 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 482 ms
42,016 KB
testcase_29 AC 567 ms
52,948 KB
testcase_30 AC 484 ms
42,068 KB
testcase_31 AC 441 ms
40,580 KB
testcase_32 AC 515 ms
45,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,d;scanf("%d",&n);
  scanf("%d",&d);
  if(n==1&&d==0){
      cout<<0<<endl;
      return 0;
  }
    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){
            v.push_back(i*i+d-j*j);
          }
        }
    }
  sort(v.begin(),v.end());
  vector<ll> vv=v;
  vv.erase(unique(vv.begin(),vv.end()),vv.end());
  ll r=vv.size();
  ll cnt[r];fill(cnt,cnt+r,0);
  ll now=0;
  for(ll i=0;i<v.size()-1;i++){
      cnt[now]++;
      if(v[i]!=v[i+1])now++;
  }
  cnt[now]++;
  v.erase(unique(v.begin(),v.end()),v.end());
    ll ans=0;
  ll anss=0;
    for(ll i=1;i<=n;i++){
        for(ll j=i;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];
            if(i==j)anss+=cnt[y];
          }
        }
    }
    
  
  ans=ans*2-anss;
    printf("%d\n",ans);
}
0