Submission #1415624
Source Code Expand
import std.stdio; import std.string; import std.conv; import std.typecons; import std.algorithm; import std.functional; import std.bigint; import std.numeric; import std.array; import std.math; import std.range; import std.container; import std.ascii; import std.concurrency; void main() { int N; readf("%d\n", &N); int[] as = readln.split.to!(int[]).map!"a-1".array; bool f(int c) { bool[] bs = as.map!(a => a>=c).array; foreach(i; 1..N) { if (bs[N-1+i-1] == bs[N-1+i]) return bs[N-1+i]; if (bs[N-1-i+1] == bs[N-1-i]) return bs[N-1-i]; } return bs[N-1] ^ (N%2==0); } int l = 0; int r = 2*N-1; while(r-l > 1) { int c = (l + r)/2; if (f(c)) { l = c; } else { r = c; } } (l+1).writeln; } // ---------------------------------------------- void times(alias fun)(int n) { // n.iota.each!(i => fun()); foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { // return n.iota.map!(i => fun()).array; T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } // fold was added in D 2.071.0 static if (__VERSION__ < 2071) { template fold(fun...) if (fun.length >= 1) { auto fold(R, S...)(R r, S seed) { static if (S.length < 2) { return reduce!fun(seed, r); } else { return reduce!fun(tuple(seed), r); } } } } // cumulativeFold was added in D 2.072.0 static if (__VERSION__ < 2072) { template cumulativeFold(fun...) if (fun.length >= 1) { import std.meta : staticMap; private alias binfuns = staticMap!(binaryFun, fun); auto cumulativeFold(R)(R range) if (isInputRange!(Unqual!R)) { return cumulativeFoldImpl(range); } auto cumulativeFold(R, S)(R range, S seed) if (isInputRange!(Unqual!R)) { static if (fun.length == 1) return cumulativeFoldImpl(range, seed); else return cumulativeFoldImpl(range, seed.expand); } private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args) { import std.algorithm.internal : algoFormat; static assert(Args.length == 0 || Args.length == fun.length, algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); static if (args.length) alias State = staticMap!(Unqual, Args); else alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns); foreach (i, f; binfuns) { static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles, { args[i] = f(args[i], e); }()), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); } static struct Result { private: R source; State state; this(R range, ref Args args) { source = range; if (source.empty) return; foreach (i, f; binfuns) { static if (args.length) state[i] = f(args[i], source.front); else state[i] = source.front; } } public: @property bool empty() { return source.empty; } @property auto front() { assert(!empty, "Attempting to fetch the front of an empty cumulativeFold."); static if (fun.length > 1) { import std.typecons : tuple; return tuple(state); } else { return state[0]; } } void popFront() { assert(!empty, "Attempting to popFront an empty cumulativeFold."); source.popFront; if (source.empty) return; foreach (i, f; binfuns) state[i] = f(state[i], source.front); } static if (isForwardRange!R) { @property auto save() { auto result = this; result.source = source.save; return result; } } static if (hasLength!R) { @property size_t length() { return source.length; } } } return Result(range, args); } } } // minElement/maxElement was added in D 2.072.0 static if (__VERSION__ < 2072) { auto minElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto minimum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b < minimum) { element = a; minimum = b; } } return element; } auto maxElement(alias map, Range)(Range r) if (isInputRange!Range && !isInfinite!Range) { alias mapFun = unaryFun!map; auto element = r.front; auto maximum = mapFun(element); r.popFront; foreach(a; r) { auto b = mapFun(a); if (b > maximum) { element = a; maximum = b; } } return element; } }
Submission Info
Submission Time | |
---|---|
Task | D - Median Pyramid Hard |
User | arkark |
Language | D (DMD64 v2.070.1) |
Score | 1300 |
Code Size | 6423 Byte |
Status | AC |
Exec Time | 73 ms |
Memory | 11668 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt |
All | 0_00.txt, 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 65 ms | 11664 KB |
1_04.txt | AC | 65 ms | 11536 KB |
1_05.txt | AC | 70 ms | 11536 KB |
1_06.txt | AC | 71 ms | 11536 KB |
1_07.txt | AC | 70 ms | 11536 KB |
1_08.txt | AC | 70 ms | 11536 KB |
1_09.txt | AC | 65 ms | 11536 KB |
1_10.txt | AC | 65 ms | 11536 KB |
1_11.txt | AC | 71 ms | 11536 KB |
1_12.txt | AC | 70 ms | 11664 KB |
1_13.txt | AC | 70 ms | 11536 KB |
1_14.txt | AC | 70 ms | 11536 KB |
1_15.txt | AC | 66 ms | 11540 KB |
1_16.txt | AC | 67 ms | 11544 KB |
1_17.txt | AC | 67 ms | 11536 KB |
1_18.txt | AC | 68 ms | 11552 KB |
1_19.txt | AC | 66 ms | 11552 KB |
1_20.txt | AC | 66 ms | 11560 KB |
1_21.txt | AC | 68 ms | 11536 KB |
1_22.txt | AC | 68 ms | 11544 KB |
1_23.txt | AC | 69 ms | 11544 KB |
1_24.txt | AC | 71 ms | 11548 KB |
1_25.txt | AC | 69 ms | 11540 KB |
1_26.txt | AC | 67 ms | 11576 KB |
1_27.txt | AC | 68 ms | 11548 KB |
1_28.txt | AC | 69 ms | 11548 KB |
1_29.txt | AC | 67 ms | 11668 KB |
1_30.txt | AC | 68 ms | 11556 KB |
1_31.txt | AC | 70 ms | 11568 KB |
1_32.txt | AC | 70 ms | 11540 KB |
1_33.txt | AC | 69 ms | 11536 KB |
1_34.txt | AC | 70 ms | 11572 KB |
1_35.txt | AC | 70 ms | 11548 KB |
1_36.txt | AC | 68 ms | 11464 KB |
1_37.txt | AC | 69 ms | 11552 KB |
1_38.txt | AC | 69 ms | 11536 KB |
1_39.txt | AC | 70 ms | 11536 KB |
1_40.txt | AC | 67 ms | 11548 KB |
1_41.txt | AC | 71 ms | 11536 KB |
1_42.txt | AC | 69 ms | 11560 KB |
1_43.txt | AC | 73 ms | 11536 KB |
1_44.txt | AC | 68 ms | 11540 KB |
1_45.txt | AC | 69 ms | 11544 KB |
1_46.txt | AC | 69 ms | 11540 KB |
1_47.txt | AC | 68 ms | 11552 KB |
1_48.txt | AC | 69 ms | 11536 KB |
1_49.txt | AC | 66 ms | 11544 KB |
1_50.txt | AC | 68 ms | 11548 KB |
1_51.txt | AC | 67 ms | 11584 KB |
1_52.txt | AC | 68 ms | 11540 KB |
1_53.txt | AC | 70 ms | 11544 KB |
1_54.txt | AC | 68 ms | 11548 KB |