結果

問題 No.702 中央値を求めよ LIMITED
コンテスト
ユーザー homesentinel
提出日時 2018-06-15 23:03:05
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,490 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 862 ms
コンパイル使用メモリ 124,588 KB
最終ジャッジ日時 2026-05-16 20:48:59
合計ジャッジ時間 2,123 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:65:1: error: 'uint32_t' does not name a type
   65 | uint32_t x = 0, y = 1, z = 2, w = 3;
      | ^~~~~~~~
main.cpp:34:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   33 | #include <climits>
  +++ |+#include <cstdint>
   34 | 
main.cpp:68:1: error: 'uint32_t' does not name a type
   68 | uint32_t generate() {
      | ^~~~~~~~
main.cpp:68:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp: In function 'void reset()':
main.cpp:78:5: error: 'x' was not declared in this scope
   78 |     x = seed;
      |     ^
main.cpp:79:5: error: 'y' was not declared in this scope; did you mean 'yn'?
   79 |     y = 1;
      |     ^
      |     yn
main.cpp:80:5: error: 'z' was not declared in this scope
   80 |     z = 2;
      |     ^
main.cpp:81:5: error: 'w' was not declared in this scope
   81 |     w = 3;
      |     ^
main.cpp: In function 'int count(ll)':
main.cpp:89:21: error: no matching function for call to 'generate()'
   89 |         if (generate() <= num) ret++;
      |             ~~~~~~~~^~
main.cpp:89:21: note: there is 1 candidate
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:63,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algo.h:4390:5: note: candidate 1: 'template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)'
 4390 |     generate(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algo.h:4390:5: note: candidate expects 3 arguments, 0 provided
main.cpp: In function 'int main()':
main.cpp:98:5: error: 'x' was not declared in this scope
   98 |     x = seed;
      |     ^

ソースコード

diff #
raw source code

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
uint32_t x = 0, y = 1, z = 2, w = 3;
int seed;

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

void reset() {
    x = seed;
    y = 1;
    z = 2;
    w = 3;
}

//num以下の数が何回登場するか
int count(ll num) {
    reset();
    int ret = 0;
    for (int i = 0; i < 10000001; i++) {
        if (generate() <= num) ret++;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> seed;
    x = seed;
    const int lim = 5000000;
    ll low = 0,high = (1ll << 32) - 1;
    int low_num = count(low);
    int high_num = count(high);


    int ii = 100;
    while(ii--){
//        if(low_num < lim && high_num >= lim){
//            break;
//        }
        ll mid = (low + high) / 2;
        int mid_num = count(mid);
        if(mid_num <= lim){
            low_num = mid_num;
            low = mid;
        }else{
            high_num = mid_num;
            high = mid;
        }

    }
    cout << high << endl;
    return 0;

}
0