結果

問題 No.702 中央値を求めよ LIMITED
ユーザー te-shte-sh
提出日時 2018-07-03 22:54:21
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,343 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 90,920 KB
実行使用メモリ 4,804 KB
最終ジャッジ日時 2023-09-03 20:35:36
合計ジャッジ時間 7,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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);

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

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

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

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

class CumulativeSum(T)
{
  size_t n;
  T[] s;

  this(T[] a)
  {
    n = a.length;
    s = new T[](n+1);
    s[0] = T(0);
    foreach (i; 0..n) s[i+1] = s[i] + a[i];
  }

  T opSlice(size_t l, size_t r) { return s[r]-s[l]; }
  size_t opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }

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

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