結果
| 問題 | No.702 中央値を求めよ LIMITED |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-03 22:54:21 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,343 bytes |
| 記録 | |
| コンパイル時間 | 683 ms |
| コンパイル使用メモリ | 102,624 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-13 01:22:17 |
| 合計ジャッジ時間 | 5,391 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 9 WA * 16 |
ソースコード
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;
}