Submission #1307211
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 times(alias fun)(int n) { foreach(i; 0..n) fun(); } auto rep(alias fun, T = typeof(fun()))(int n) { T[] res = new T[n]; foreach(ref e; res) e = fun(); return res; } void main() { int N, K; readf("%d %d\n", &N, &K); int[] ary = readln.split.to!(int[]); bool[][] dp1 = new bool[][](N+1, K); dp1[0][0] = true; foreach(i, a; ary) { dp1[i+1][] = dp1[i][]; foreach(j; 0..K-a) { dp1[i+1][j+a] |= dp1[i][j]; } } bool[][] dp2 = new bool[][](N+1, K); dp2[0][0] = true; foreach(i, a; ary.retro.array) { dp2[i+1][] = dp2[i][]; foreach(j; 0..K-a) { dp2[i+1][j+a] |= dp2[i][j]; } } int ans = N; foreach(i, a; ary) { bool[] po1 = dp1[i]; bool[] po2 = dp2[N-i-1]; int l = 0; int r = K-a; int s = po2[max(0, r)..$].count!"a".to!int; while(l<K) { if (po1[l] && s>0) { ans--; break; } l++; r--; s -= (r+a<K && po2[r+a]) ? 1:0; s += (r>=0 && po2[r]) ? 1:0; } } ans.writeln; } // ---------------------------------------------- // 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 - No Need |
User | arkark |
Language | D (DMD64 v2.070.1) |
Score | 600 |
Code Size | 6765 Byte |
Status | AC |
Exec Time | 185 ms |
Memory | 82300 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 300 / 300 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
Subtask | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
1_003.txt | AC | 1 ms | 256 KB |
1_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 2 ms | 764 KB |
1_009.txt | AC | 2 ms | 764 KB |
1_010.txt | AC | 2 ms | 764 KB |
1_011.txt | AC | 1 ms | 380 KB |
1_012.txt | AC | 2 ms | 764 KB |
1_013.txt | AC | 1 ms | 380 KB |
1_014.txt | AC | 1 ms | 380 KB |
1_015.txt | AC | 2 ms | 764 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 1 ms | 256 KB |
1_019.txt | AC | 2 ms | 764 KB |
1_020.txt | AC | 1 ms | 380 KB |
1_021.txt | AC | 2 ms | 508 KB |
1_022.txt | AC | 1 ms | 380 KB |
1_023.txt | AC | 1 ms | 256 KB |
1_024.txt | AC | 2 ms | 508 KB |
1_025.txt | AC | 2 ms | 764 KB |
2_026.txt | AC | 1 ms | 256 KB |
2_027.txt | AC | 1 ms | 320 KB |
2_028.txt | AC | 1 ms | 320 KB |
2_029.txt | AC | 145 ms | 81916 KB |
2_030.txt | AC | 185 ms | 81020 KB |
2_031.txt | AC | 58 ms | 81788 KB |
2_032.txt | AC | 4 ms | 892 KB |
2_033.txt | AC | 58 ms | 80764 KB |
2_034.txt | AC | 3 ms | 764 KB |
2_035.txt | AC | 3 ms | 764 KB |
2_036.txt | AC | 80 ms | 81276 KB |
2_037.txt | AC | 2 ms | 508 KB |
2_038.txt | AC | 1 ms | 508 KB |
2_039.txt | AC | 2 ms | 508 KB |
2_040.txt | AC | 53 ms | 81916 KB |
2_041.txt | AC | 44 ms | 41596 KB |
2_042.txt | AC | 58 ms | 41724 KB |
2_043.txt | AC | 36 ms | 27004 KB |
2_044.txt | AC | 41 ms | 34684 KB |
2_045.txt | AC | 23 ms | 20732 KB |
2_046.txt | AC | 67 ms | 42364 KB |
2_047.txt | AC | 94 ms | 42236 KB |
2_048.txt | AC | 124 ms | 82300 KB |
2_049.txt | AC | 109 ms | 81660 KB |
2_050.txt | AC | 98 ms | 81276 KB |