結果
問題 | No.800 四平方定理 |
ユーザー | hanbei_dayo |
提出日時 | 2020-08-11 19:52:16 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,065 ms / 2,000 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 875 ms |
コンパイル使用メモリ | 104,672 KB |
実行使用メモリ | 45,760 KB |
最終ジャッジ日時 | 2024-04-17 17:31:54 |
合計ジャッジ時間 | 15,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
6,812 KB |
testcase_01 | AC | 14 ms
6,940 KB |
testcase_02 | AC | 11 ms
6,944 KB |
testcase_03 | AC | 11 ms
6,940 KB |
testcase_04 | AC | 12 ms
6,944 KB |
testcase_05 | AC | 12 ms
6,940 KB |
testcase_06 | AC | 15 ms
6,940 KB |
testcase_07 | AC | 12 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 14 ms
6,940 KB |
testcase_10 | AC | 498 ms
24,736 KB |
testcase_11 | AC | 515 ms
27,016 KB |
testcase_12 | AC | 552 ms
29,328 KB |
testcase_13 | AC | 432 ms
19,448 KB |
testcase_14 | AC | 471 ms
24,912 KB |
testcase_15 | AC | 558 ms
28,408 KB |
testcase_16 | AC | 470 ms
29,484 KB |
testcase_17 | AC | 469 ms
25,404 KB |
testcase_18 | AC | 613 ms
29,076 KB |
testcase_19 | AC | 617 ms
28,548 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 611 ms
28,912 KB |
testcase_23 | AC | 1,050 ms
45,760 KB |
testcase_24 | AC | 900 ms
35,056 KB |
testcase_25 | AC | 1,065 ms
43,648 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 870 ms
34,716 KB |
testcase_29 | AC | 973 ms
43,660 KB |
testcase_30 | AC | 861 ms
34,880 KB |
testcase_31 | AC | 793 ms
33,752 KB |
testcase_32 | AC | 906 ms
44,264 KB |
ソースコード
#include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<string> #include<utility> #include<map> #include<set> #include<queue> #include<stack> #include<functional> #include<math.h> #include<random> #include <bitset> using namespace std; #define N (1000000000+7) //#define N 998244353 #define INF 1e16 typedef long long ll; typedef pair<ll,ll> P; typedef pair<int,P> Q; const int inf = (int)1e9; ll gcd(ll a, ll b) { if (b > a) { ll tmp = b; b = a; a = tmp; } if (a%b == 0)return b; else return gcd(b, a%b); } int main(void){ ll n,d; cin>>n>>d; vector<int>v1,v2; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ v1.push_back(i*i+j*j); } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(d+i*i-j*j>=0 && d+i*i-j*j<=2*n*n){ v2.push_back(d+i*i-j*j); } } } ll ans = 0; sort(v2.begin(),v2.end()); for(int i=0;i<v1.size();i++){ int index1 = upper_bound(v2.begin(),v2.end(),v1[i])-v2.begin(); int index2 = lower_bound(v2.begin(),v2.end(),v1[i])-v2.begin(); ans+=index1-index2; } cout<<ans<<endl; return 0; }