結果

問題 No.2368 I love a square root of 2
ユーザー 👑 hitonanodehitonanode
提出日時 2023-06-30 22:48:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 117,500 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2023-09-21 17:00:58
合計ジャッジ時間 2,136 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 21 ms
5,168 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 30 ms
5,088 KB
testcase_14 AC 30 ms
5,248 KB
testcase_15 AC 33 ms
5,220 KB
testcase_16 AC 23 ms
5,100 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 24 ms
5,088 KB
testcase_22 AC 30 ms
5,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
using lint = long long;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

int main() {
    lint N;
    cin >> N;


    lint fng = 0;

    const double sqrt2 = sqrt(2.0);

    int ng = sqrt(sqrt2 * N * 2) - 10, ok = 2e5;

    auto f = [&](int l) {
        lint ret = 0;
        REP(x, l + 1) {
            double u = l - sqrt2 * x;
            if (u >= 0) ret += u + 1;
            else {
                break;
            }
        }
        return ret;
    };

    while (ok - ng > 1) {
        const lint c = (ok + ng) / 2;
        if (auto fc = f(c); fc >= N) {
            ok = c;
        } else {
            fng = fc, ng = c;
        }
    }

    const lint req = N - fng;
    vector<tuple<double, int, int>> vs;
    REP(x, ok + 1) {
        int y = ok - sqrt2 * x;
        if (y < 0) break;
        if (auto t = x * sqrt2 + y; t > ok - 1) vs.emplace_back(t, x, y);
    }

    partial_sort(vs.begin(), vs.begin() + req, vs.end());

    auto ret = vs.at(req - 1);
    cout << get<2>(ret) << ' ' << get<1>(ret) << '\n';
}
0