結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
やむなく
|
| 提出日時 | 2019-03-17 22:18:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,803 ms / 2,000 ms |
| コード長 | 768 bytes |
| コンパイル時間 | 1,399 ms |
| コンパイル使用メモリ | 178,640 KB |
| 実行使用メモリ | 72,684 KB |
| 最終ジャッジ日時 | 2024-07-07 23:59:28 |
| 合計ジャッジ時間 | 23,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
typedef long long LL;
typedef long double LD;
int main(){
int n,d;
cin >> n >> d;
vector<int> p(n*n);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
p[(i-1)*n+j-1]=i*i+j*j;
}
}
sort(all(p));
map<int,int> mp;
int count=1;
for(int i=1;i<n*n;i++){
if(p[i-1]==p[i]){
count++;
}else{
mp[p[i-1]]=count;
count=1;
}
}
mp[p[n*n-1]]=count;
LL ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
auto itr=mp.find(i*i-j*j+d);
if(itr!=mp.end()) ans+=itr->second;
}
}
cout << ans << endl;
return 0;
}
やむなく