結果

問題 No.702 中央値を求めよ LIMITED
ユーザー xuzijian629xuzijian629
提出日時 2018-09-05 14:41:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 572 ms / 5,000 ms
コード長 2,210 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 85,148 KB
実行使用メモリ 14,804 KB
最終ジャッジ日時 2023-08-14 21:43:46
合計ジャッジ時間 17,515 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 554 ms
14,708 KB
testcase_01 AC 521 ms
13,336 KB
testcase_02 AC 542 ms
14,804 KB
testcase_03 AC 553 ms
13,812 KB
testcase_04 AC 519 ms
14,564 KB
testcase_05 AC 520 ms
13,840 KB
testcase_06 AC 535 ms
13,772 KB
testcase_07 AC 532 ms
13,936 KB
testcase_08 AC 522 ms
13,628 KB
testcase_09 AC 532 ms
13,776 KB
testcase_10 AC 538 ms
14,128 KB
testcase_11 AC 555 ms
13,692 KB
testcase_12 AC 541 ms
14,556 KB
testcase_13 AC 526 ms
13,336 KB
testcase_14 AC 524 ms
13,840 KB
testcase_15 AC 530 ms
13,904 KB
testcase_16 AC 532 ms
13,812 KB
testcase_17 AC 529 ms
14,640 KB
testcase_18 AC 533 ms
13,620 KB
testcase_19 AC 532 ms
14,240 KB
testcase_20 AC 523 ms
14,220 KB
testcase_21 AC 544 ms
13,752 KB
testcase_22 AC 535 ms
13,984 KB
testcase_23 AC 572 ms
14,608 KB
testcase_24 AC 523 ms
14,260 KB
testcase_25 AC 566 ms
13,808 KB
testcase_26 AC 542 ms
13,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

uint32_t x = 0, y = 1, z = 2, w = 3;
uint32_t generate() {
    uint32_t t = (x^(x<<11));
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w;
}

int main() {
    uint32_t seed;
    cin >> seed;
    x = seed;
    
    vector<uint32_t> tmp, reserved;
    int tmpsize = 1000001;
    for (int i = 0; i < tmpsize; i++) {
        tmp.push_back(generate());
    }
    sort(tmp.begin(), tmp.end());
    for (int i = 250000; i <= 750000; i++) {
        reserved.push_back(tmp[i]);
    }

    double off = 0;
    int small_cnt = 0;
    uint32_t min = reserved.front(), max = reserved.back(), mid = reserved[250000];
    for (int i = 0; i < 9; i++) {
        assert(reserved.size() == 500001);
        for (int j = 0; j < 1000000; j++) {
            uint32_t u1 = generate();
            if (u1 <= mid) {
                off -= 0.5;
                if (u1 > min) {
                    small_cnt++;
                    reserved.push_back(u1);
                }
            }
            if (u1 > mid) {
                    off += 0.5;
                if (u1 < max) {
                    reserved.push_back(u1);
                }
            }
        }
        sort(reserved.begin(), reserved.end());
        assert(mid == reserved[250000 + small_cnt]);
        int new_mid_ind = 250000 + small_cnt + int(off);
//        cout << new_mid_ind << " " << reserved.size() << endl;
        tmp.clear();
        for (int k = new_mid_ind - 250000; k <= new_mid_ind + 250000; k++) {
            assert(k >= 0 && k < reserved.size());
            tmp.push_back(reserved[k]);
        }
        reserved = vector<uint32_t>(tmp);
        mid = reserved[250000];
        min = reserved.front();
        max = reserved.back();
        off = 0;
        small_cnt = 0;
    }
    cout << mid << endl;
}
0