結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
hamray
|
| 提出日時 | 2019-03-17 22:15:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,206 ms / 2,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 714 ms |
| コンパイル使用メモリ | 72,612 KB |
| 実行使用メモリ | 36,068 KB |
| 最終ジャッジ日時 | 2024-07-07 23:50:11 |
| 合計ジャッジ時間 | 15,494 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <cstring>
#include <functional>
#include <tuple>
using namespace std;
using ll = long long;
vector<ll> v;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
ll N, D; cin >> N >> D;
for(ll i=1; i<=N; ++i){
for(ll j=1; j<=N; ++j){
v.push_back(i*i+j*j);
}
}
sort(v.begin(), v.end());
ll ans=0;
for(ll i=1; i<=N; ++i){
for(ll j=1; j<=N; ++j){
if(D+i*i-j*j<0) break;
ans += upper_bound(v.begin(), v.end(), D+i*i-j*j) - lower_bound(v.begin(), v.end(), D+i*i-j*j);
}
}
cout << ans << endl;
return 0;
}
hamray