結果
問題 | No.800 四平方定理 |
ユーザー | HaraTakashi |
提出日時 | 2022-01-29 11:12:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,281 ms / 2,000 ms |
コード長 | 2,890 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 202,596 KB |
実行使用メモリ | 20,600 KB |
最終ジャッジ日時 | 2023-08-30 08:38:09 |
合計ジャッジ時間 | 20,216 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
4,376 KB |
testcase_01 | AC | 17 ms
4,376 KB |
testcase_02 | AC | 12 ms
4,380 KB |
testcase_03 | AC | 13 ms
4,380 KB |
testcase_04 | AC | 12 ms
4,376 KB |
testcase_05 | AC | 14 ms
4,376 KB |
testcase_06 | AC | 19 ms
4,376 KB |
testcase_07 | AC | 14 ms
4,376 KB |
testcase_08 | AC | 10 ms
4,376 KB |
testcase_09 | AC | 16 ms
4,376 KB |
testcase_10 | AC | 585 ms
11,468 KB |
testcase_11 | AC | 608 ms
11,428 KB |
testcase_12 | AC | 655 ms
11,708 KB |
testcase_13 | AC | 518 ms
7,768 KB |
testcase_14 | AC | 554 ms
11,856 KB |
testcase_15 | AC | 659 ms
12,632 KB |
testcase_16 | AC | 558 ms
12,324 KB |
testcase_17 | AC | 562 ms
13,164 KB |
testcase_18 | AC | 747 ms
12,896 KB |
testcase_19 | AC | 744 ms
11,656 KB |
testcase_20 | AC | 1 ms
4,376 KB |
testcase_21 | AC | 1 ms
4,380 KB |
testcase_22 | AC | 747 ms
12,048 KB |
testcase_23 | AC | 1,269 ms
20,492 KB |
testcase_24 | AC | 1,054 ms
12,448 KB |
testcase_25 | AC | 1,281 ms
20,600 KB |
testcase_26 | AC | 1 ms
4,380 KB |
testcase_27 | AC | 2 ms
4,376 KB |
testcase_28 | AC | 1,050 ms
12,116 KB |
testcase_29 | AC | 1,184 ms
19,652 KB |
testcase_30 | AC | 1,051 ms
12,008 KB |
testcase_31 | AC | 974 ms
12,868 KB |
testcase_32 | AC | 1,094 ms
20,368 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using T = tuple<int, int, int>; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl; #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using T = tuple<int, int, int>; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define db(a, b) cout << #a << ": " << a << " " << #b << ": " << b << endl; int main() { ll n, d; cin >> n >> d; vector<int> ls; for (int w = 1; w <= n; ++w) { for (int z = 1; z <= n; ++z) { int t = w * w - z * z + d; if (t < 0) break; ls.push_back(t); } } sort(al(ls)); ll ans = 0; for (int x = 1; x <= n; ++x) { for (int y = 1; y <= n; ++y) { int s = x * x + y * y; int now = upper_bound(al(ls), s) - lower_bound(al(ls), s); ans += now; } } cout << ans << endl; return 0; } // int main() { // ll n, d; // cin >> n >> d; // unordered_map<int, int> mp; // for (int x = 1; x <= n; ++x) { // for (int y = 1; y <= n; ++y) { // int s = x * x + y * y; // mp[s]++; // } // } // ll ans = 0; // for (int z = 1; z <= n; ++z) { // for (int w = 1; w <= n; ++w) { // int t = w * w - z * z + d; // if (t < 0) break; // ans += mp[t]; // } // } // cout << ans << endl; // return 0; // } // int main() { // ll n, d; // cin >> n >> d; // const int MX = n * n + n * n; // vector<int> cnt1(MX + 1), cnt2(MX + 1); // for (int x = 1; x <= n; ++x) { // for (int y = 1; y <= n; ++y) { // int s = x * x + y * y; // cnt1[s]++; // } // } // ll ans = 0; // for (int w = 1; w <= n; ++w) { // for (int z = 1; z <= n; ++z) { // int t = w * w - z * z + d; // if (t < 0) break; // if (t > MX) continue; // cnt2[t]++; // } // } // rrep(i, MX) ans += ll(cnt1[i]) * cnt2[i]; // cout << ans << endl; // return 0; // } // int main() { // ll n, d; // cin >> n >> d; // unordered_map<int, int> mp; // for (int x = 1; x <= n; ++x) { // for (int y = 1; y <= n; ++y) { // int s = x * x + y * y; // mp[s]++; // } // } // ll ans = 0; // for (int z = 1; z <= n; ++z) { // for (int w = 1; w <= n; ++w) { // int t = w * w - z * z + d; // if (t < 0) break; // ans += mp[t]; // } // } // cout << ans << endl; // return 0; // }