結果

問題 No.702 中央値を求めよ LIMITED
ユーザー tetsutetsu
提出日時 2018-06-15 23:22:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,132 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 164,632 KB
実行使用メモリ 7,784 KB
最終ジャッジ日時 2023-09-13 05:19:25
合計ジャッジ時間 13,016 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,233 ms
4,376 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>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define u32 unsigned int
bool test(u32 s, u32 m) {
  u32 x=s, y=1, z=2, w=3;
  ll bigger = 0;
  ll smaller = 0;
  ll eq = 0;
  rep(_, 1e7+1) {
    ll t = (x^(x<<11));
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    if(w>m) {
      bigger++;
    } else if(w==m) {
      eq++;
    } else {
      smaller++;
    }
  }
  return bigger>=smaller;
}
bool valid(u32 s, u32 m) {
  u32 x=s, y=1, z=2, w=3;
  ll bigger = 0;
  ll smaller = 0;
  ll eq = 0;
  rep(_, 1e7+1) {
    ll t = (x^(x<<11));
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    if(w>m) {
      bigger++;
    } else if(w==m) {
      eq++;
    } else {
      smaller++;
    }
  }
  return bigger==smaller;
}

int main() {
  u32 s; cin >> s;
  u32 u = 4294967295; // 2**32=4294967296
  u32 l = 0;
  while(u-l>1) {
    u32 mid = (u+l)/2;
    if(test(s, mid)) {
      l = mid;
    } else {
      u = mid;
    }
  }
  u32 ans;
  if(valid(s, u)) ans = u;
  else ans = l;
  cout << ans << endl;
  return 0;
}
0