結果

問題 No.702 中央値を求めよ LIMITED
ユーザー tnakao0123tnakao0123
提出日時 2018-06-18 20:28:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 582 ms / 5,000 ms
コード長 1,169 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 84,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 09:40:20
合計ジャッジ時間 16,266 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 529 ms
6,812 KB
testcase_01 AC 582 ms
6,940 KB
testcase_02 AC 528 ms
6,940 KB
testcase_03 AC 533 ms
6,940 KB
testcase_04 AC 527 ms
6,944 KB
testcase_05 AC 530 ms
6,940 KB
testcase_06 AC 525 ms
6,940 KB
testcase_07 AC 532 ms
6,944 KB
testcase_08 AC 570 ms
6,940 KB
testcase_09 AC 545 ms
6,940 KB
testcase_10 AC 527 ms
6,944 KB
testcase_11 AC 526 ms
6,944 KB
testcase_12 AC 520 ms
6,940 KB
testcase_13 AC 535 ms
6,940 KB
testcase_14 AC 534 ms
6,940 KB
testcase_15 AC 530 ms
6,944 KB
testcase_16 AC 524 ms
6,944 KB
testcase_17 AC 526 ms
6,940 KB
testcase_18 AC 538 ms
6,940 KB
testcase_19 AC 541 ms
6,940 KB
testcase_20 AC 528 ms
6,940 KB
testcase_21 AC 527 ms
6,940 KB
testcase_22 AC 540 ms
6,944 KB
testcase_23 AC 541 ms
6,944 KB
testcase_24 AC 566 ms
6,944 KB
testcase_25 AC 520 ms
6,944 KB
testcase_26 AC 518 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |   scanf("%u", &seed);
      |   ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 702.cc: No.702 中央値を求めよ LIMITED - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 10000001;
const int MED = (N + 1) / 2;

/* typedef */

typedef uint32_t ui;
typedef long long ll;

/* global variables */

ui x = 0, y = 1, z = 2, w = 3;

/* subroutines */

inline ui generate(ui &x, ui &y, ui &z, ui &w) {
  ui t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  return w;
}

/* main */

int main() {
  ui seed;
  scanf("%u", &seed);

  ll l = -1, r = (1LL << 32) - 1;
  while (l + 1 < r) {
    ll m = (l + r) / 2;

    int cnt = 0;
    ui x = seed, y = 1, z = 2, w = 3;
    for (int i = 0; i < N; i++) {
      ui ai = generate(x, y, z, w);
      if (ai <= m) cnt++;
    }

    if (cnt >= MED) r = m;
    else l = m;
  }

  printf("%lld\n", r);
  return 0;
}
0