結果

問題 No.800 四平方定理
ユーザー ttttanttttan
提出日時 2019-03-17 23:17:12
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 924 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 153,552 KB
実行使用メモリ 60,660 KB
最終ジャッジ日時 2023-09-22 10:30:41
合計ジャッジ時間 10,513 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 9 ms
4,376 KB
testcase_07 AC 10 ms
4,588 KB
testcase_08 AC 10 ms
4,748 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 290 ms
31,320 KB
testcase_11 AC 291 ms
30,364 KB
testcase_12 AC 327 ms
34,960 KB
testcase_13 AC 237 ms
23,304 KB
testcase_14 AC 255 ms
26,208 KB
testcase_15 AC 322 ms
34,576 KB
testcase_16 AC 255 ms
25,888 KB
testcase_17 AC 255 ms
25,888 KB
testcase_18 AC 362 ms
39,552 KB
testcase_19 AC 365 ms
39,876 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 372 ms
40,460 KB
testcase_23 AC 621 ms
60,660 KB
testcase_24 AC 469 ms
42,256 KB
testcase_25 AC 625 ms
59,716 KB
testcase_26 RE -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 483 ms
42,176 KB
testcase_29 AC 567 ms
52,696 KB
testcase_30 AC 482 ms
42,136 KB
testcase_31 AC 439 ms
39,660 KB
testcase_32 AC 549 ms
46,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,d;scanf("%d",&n);
  scanf("%d",&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){
            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