結果
問題 | No.800 四平方定理 |
ユーザー |
![]() |
提出日時 | 2020-05-17 09:12:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 954 ms / 2,000 ms |
コード長 | 1,684 bytes |
コンパイル時間 | 1,959 ms |
コンパイル使用メモリ | 173,956 KB |
実行使用メモリ | 67,580 KB |
最終ジャッジ日時 | 2024-09-24 19:49:10 |
合計ジャッジ時間 | 16,177 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define VIN(v) for(auto&elem_: (v) )cin>>elem_ #define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl #define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl #define ALL(a) (a).begin(),(a).end() const ll MOD = 1000000007ll; const int IINF = numeric_limits<int>::max()/2-1; const ll LINF = numeric_limits<ll>::max()/2-1; #define FIX(a) ((a)%MOD+MOD)%MOD int n,d; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>d;//1<=n<=2000 vl a,b; FOR(x,1,n+1) FOR(y,x,n+1){ a.emplace_back(pow(x,2)+pow(y,2)); if(x!=y) a.emplace_back(pow(x,2)+pow(y,2)); b.emplace_back(pow(y,2)-pow(x,2)); if(x!=y) b.emplace_back(pow(x,2)-pow(y,2)); //x2+y2+z2-w2 } sort(ALL(a)); sort(ALL(b)); ll ans = 0; ll sz = a.size(); REP(i,sz){ ll tmp = upper_bound(ALL(b), d-a[i]) - lower_bound(ALL(b), d-a[i]); ans += tmp; } cout << ans << endl; return 0; }