結果

問題 No.800 四平方定理
ユーザー ttttanttttan
提出日時 2019-03-17 22:22:18
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 807 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 159,576 KB
実行使用メモリ 115,592 KB
最終ジャッジ日時 2023-09-22 07:37:25
合計ジャッジ時間 22,320 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,416 KB
testcase_01 AC 20 ms
5,156 KB
testcase_02 AC 13 ms
4,792 KB
testcase_03 AC 15 ms
4,808 KB
testcase_04 AC 16 ms
4,784 KB
testcase_05 AC 18 ms
5,100 KB
testcase_06 AC 23 ms
5,432 KB
testcase_07 AC 32 ms
6,300 KB
testcase_08 AC 42 ms
7,336 KB
testcase_09 AC 20 ms
5,272 KB
testcase_10 AC 1,425 ms
62,904 KB
testcase_11 AC 1,372 ms
61,048 KB
testcase_12 AC 1,654 ms
70,180 KB
testcase_13 AC 994 ms
48,108 KB
testcase_14 AC 1,079 ms
53,964 KB
testcase_15 AC 1,668 ms
70,200 KB
testcase_16 AC 1,076 ms
53,268 KB
testcase_17 AC 1,080 ms
54,332 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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){
            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];
  ans=ans*2+anss;
    printf("%d\n",ans);
}
0