結果

問題 No.781 円周上の格子点の数え上げ
ユーザー @abcde@abcde
提出日時 2019-05-19 16:57:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,653 bytes
コンパイル時間 3,456 ms
コンパイル使用メモリ 166,080 KB
実行使用メモリ 42,836 KB
最終ジャッジ日時 2023-10-17 07:55:51
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
42,836 KB
testcase_01 AC 59 ms
42,836 KB
testcase_02 AC 60 ms
42,836 KB
testcase_03 AC 60 ms
42,836 KB
testcase_04 AC 60 ms
42,836 KB
testcase_05 AC 59 ms
42,836 KB
testcase_06 AC 60 ms
42,836 KB
testcase_07 AC 59 ms
42,836 KB
testcase_08 AC 59 ms
42,836 KB
testcase_09 AC 59 ms
42,836 KB
testcase_10 AC 59 ms
42,836 KB
testcase_11 AC 60 ms
42,836 KB
testcase_12 AC 64 ms
42,836 KB
testcase_13 AC 70 ms
42,836 KB
testcase_14 AC 61 ms
42,836 KB
testcase_15 AC 61 ms
42,836 KB
testcase_16 AC 61 ms
42,836 KB
testcase_17 AC 65 ms
42,836 KB
testcase_18 AC 62 ms
42,836 KB
testcase_19 AC 63 ms
42,836 KB
testcase_20 AC 61 ms
42,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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;
    
}
0