結果

問題 No.702 中央値を求めよ LIMITED
ユーザー te-shte-sh
提出日時 2018-07-04 10:14:36
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 187 ms / 5,000 ms
コード長 998 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 91,036 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-09-03 20:36:06
合計ジャッジ時間 7,075 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

const n = 10000001;

void main()
{
  uint seed; readV(seed);

  init(seed);
  auto a = new int[](1<<16);
  foreach (_; 0..n) {
    auto r = generate();
    ++a[r>>16];
  }

  auto i = 0, s = 0;
  for (; i < (1<<16); ++i) {
    if (s+a[i] >= (n+1)/2) break;
    s += a[i];
  }

  init(seed);
  a[] = 0;
  foreach (_; 0..n) {
    auto r = generate();
    if ((r>>16) == i)
      ++a[r&((1<<16)-1)];
  }

  foreach (j; 0..1<<16) {
    s += a[j];
    if (s >= (n+1)/2) {
      writeln(cast(uint)((i<<16)|j));
      return;
    }
  }
}

uint x, y, z, w;

void init(uint seed)
{
  x = seed;
  y = 1;
  z = 2;
  w = 3;
}
uint generate() {
  uint t = (x^(x<<11));
  x = y;
  y = z;
  z = w;
  w = (w^(w>>19))^(t^(t>>8)); 
  return w;
}
0