結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
ttttan
|
| 提出日時 | 2019-03-17 22:02:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 771 bytes |
| コンパイル時間 | 2,520 ms |
| コンパイル使用メモリ | 208,516 KB |
| 最終ジャッジ日時 | 2025-01-06 23:00:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 TLE * 8 |
ソースコード
#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;
}
ttttan