結果

問題 No.702 中央値を求めよ LIMITED
ユーザー PachicobuePachicobue
提出日時 2018-09-03 16:14:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 723 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 194,576 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-16 23:10:29
合計ジャッジ時間 15,822 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,571 ms
5,248 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
int main()
{
    uint32_t seed, inf = 0, sup = ~0U;
    std::cin >> seed;
    constexpr uint32_t HALF = 5000001, ALL = 2 * HALF - 1;
    auto ok = [&](const uint32_t m) {
        uint32_t x = seed, y = 1, z = 2, w = 3, l = 0, e = 0, u = 0;
        auto gen = [&]() { const uint32_t t = (x ^ (x << 11)); return x=y,y=z,z=w,w=(w^(w>>19))^(t^(t>>8)); };
        for (uint32_t i = 0, v; i < ALL; i++) { v = gen(), (v < m ? l : v == m ? e : u)++; }
        return l >= HALF ? 1 : u >= HALF ? -1 : 0;
    };
    while (sup - inf > 1) {
        const uint32_t mid = (sup + inf) / 2;
        if (ok(mid) == 0) { return std::cout << mid << std::endl, 0; }
        (ok(mid) == -1 ? inf : sup) = mid;
    }
}
0