結果
| 問題 |
No.781 円周上の格子点の数え上げ
|
| コンテスト | |
| ユーザー |
@abcde
|
| 提出日時 | 2019-05-19 16:57:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 1,653 bytes |
| コンパイル時間 | 1,494 ms |
| コンパイル使用メモリ | 165,968 KB |
| 実行使用メモリ | 42,752 KB |
| 最終ジャッジ日時 | 2024-09-17 06:29:23 |
| 合計ジャッジ時間 | 3,547 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
// TLE版(7134[ms]).
// #include <bits/stdc++.h>
// using namespace std;
// const int LIMIT = 1e7;
//
// int main() {
//
// // 1. 入力情報取得.
// int A, B;
// cin >> A >> B;
//
// // 2. f(R) の 最大値 を 計算.
// // TLE防止のため, 事前に, 半径R の 候補 を保存.
// map<int, int> m;
// m[0]++;
// for(int x = 1; x < sqrt(LIMIT) + 1; x++){
// m[x * x + 0 * 0]++, m[x * x + x * x]++;
// for(int y = x + 1; y < sqrt(LIMIT) + 1; y++){
// m[x * x + y * y] += 2;
// }
// }
// // for(auto &p : m) cout << p.first << " " << p.second << endl;
// int ans = 0;
// for(int r = A; r <= B; r++) ans = max(ans, m[r]);
//
// // 3. 後処理.
// cout << (ans * 4) << endl;
// return 0;
//
// }
// TODO: 高速化.
// mapを廃止して, 配列に変更したところ, 7134[ms] -> 103[ms] に改善.
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e7;
int f[MAX + 1];
int main() {
// 1. 入力情報取得.
int A, B;
scanf("%d %d", &A, &B);
// 2. f(R) の 最大値 を 計算.
for(int x = 1; x <= sqrt(MAX) + 1; x++){
int l = x * x + 0 * 0;
int m = x * x + x * x;
if(l <= MAX) f[l]++;
if(m <= MAX) f[m]++;
for(int y = x + 1; y <= sqrt(MAX) + 1; y++){
int n = x * x + y * y;
if(n <= MAX) f[n] += 2;
}
}
// 3. max(f(A), f(A + 1), ... , f(B)) を計算.
int ans = 0;
for(int r = A; r <= B; r++) ans = max(ans, f[r]);
// 3. 後処理.
printf("%d\n", ans * 4);
return 0;
}
@abcde