結果

問題 No.2368 I love a square root of 2
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2021-06-23 00:08:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,160 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 91,324 KB
実行使用メモリ 6,988 KB
最終ジャッジ日時 2023-09-21 13:00:30
合計ジャッジ時間 2,156 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 19 ms
6,988 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 16 ms
6,100 KB
testcase_14 AC 16 ms
6,100 KB
testcase_15 AC 17 ms
6,376 KB
testcase_16 AC 13 ms
6,072 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 18 ms
6,848 KB
testcase_22 AC 18 ms
6,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vl = vector<ll>;

void merge_sort(Vl& X, const Vl& Y, int l, int r)
{
    //cout << l << ' ' << r << endl;
    if (l == r - 1 || l == r) {
        return;
    }
    merge_sort(X, Y, l, (l + r) / 2);
    merge_sort(X, Y, (l + r) / 2, r);
    int p = l;
    int q = (l + r) / 2;
    Vl Q(r - l);
    for (int i = l; i < r; i++) {
        if (p == (l + r) / 2) {
            Q[i - l] = X[q];
            q++;
            continue;
        }
        if (q == r) {
            Q[i - l] = X[p];
            p++;
            continue;
        }
        ll& a = X[p];
        ll& b = X[q];
        if ((a < b) == (((Y[(int)b] - Y[(int)a]) * (Y[(int)b] - Y[(int)a])) < (2ll * (b - a) * (b - a)))) {
            Q[i - l] = a;
            p++;
        } else {
            Q[i - l] = b;
            q++;
        }
    }
    for (int i = l; i < r; i++) {
        X[i] = Q[i - l];
    }
}

int main()
{
    ll cnt = 0;
    ll pk = 1;
    double s2 = 1.41421356;
    ll N;
    cin >> N;
    /*for (ll i = 0; i <= 1159; i++) {
        calc2(1158, i);
        calc2(1159, i);
        calc2(i, 1158);
        calc2(i, 1159);
    }
    return 0;*/
    while (true) {
        ll kj = pk / s2;
        while (kj > 0 && kj * kj * 2 >= pk * pk) {
            kj--;
        }
        while (kj * kj * 2 <= pk * pk) {
            kj++;
        }
        cnt += kj;
        if (cnt >= N) {
            break;
        }
        pk++;
    }
    //cout << "end " << pk << endl;
    Vl X;
    Vl Y;
    vector<pair<double, ll>> Z;
    ll now = 0;
    for (ll i = 0; i * i * 2 <= pk * pk; i++) {
        while (now * now <= i * i * 2) {
            now++;
        }
        now--;
        Y.push_back(now);
        X.push_back(i);
        Z.push_back(make_pair(sqrt(2) * i - now, i));
    }
    ll kj = X.size();
    
    sort(Z.begin(), Z.end());
    
    ll ans2 = Z[static_cast<int>(N + kj - cnt - 1)].second;
    ll ans1 = Y[ans2] + 1;
    cout << pk - ans1 << ' ' << ans2 << endl;
}
0