Submission #2049861


Source Code Expand

import std.stdio;
import std.string;
import std.format;
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;
import std.traits;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

const long INF = long.max/3;
const long MOD = 10L^^9+7;

void main() {
    int N, K;
    scanln(N, K);
    long[] vs = readln.split.to!(long[]);

    long[][] dp = new long[][](K+1, N);
    foreach(i; 0..K+1) {
        dp[i][] = INF;
    }
    foreach(i; 0..N) {
        foreach(_j; 0..K) {
            int j = K-_j-1;
            auto p = dp[j].assumeSorted.lowerBound(INF);
            if (p.length == 0) continue;
            dp[j+1][p.length-1] = -INF;
        }
        foreach(j; 0..K+1) {
            auto p = dp[j].assumeSorted.lowerBound(vs[i]);
            dp[j][p.length] = vs[i];
        }
    }

    dp.back.count!(a => a<INF).writeln;

}

// ----------------------------------------------

void scanln(Args...)(auto ref Args args) {
    import std.meta;
    template getFormat(T) {
        static if (isIntegral!T) {
            enum getFormat = "%d";
        } else static if (isFloatingPoint!T) {
            enum getFormat = "%g";
        } else static if (isSomeString!T || isSomeChar!T) {
            enum getFormat = "%s";
        } else {
            static assert(false);
        }
    }
    enum string str = [staticMap!(getFormat, Args)].join(" ") ~ "\n";
    // readf!str(args);
    mixin("str.readf(" ~ Args.length.iota.map!(i => "&args[%d]".format(i)).join(", ") ~ ");");
}

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

T ceil(T)(T x, T y) if (__traits(isIntegral, T)) {
    // `(x+y-1)/y` will only work for positive numbers ...
    T t = x / y;
    if (t * y < x) t++;
    return t;
}

T floor(T)(T x, T y) if (__traits(isIntegral, T)) {
    T t = x / y;
    if (t * y > x) t--;
    return t;
}

// 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 B - だんだん強く
User arkark
Language D (DMD64 v2.070.1)
Score 800
Code Size 7535 Byte
Status AC
Exec Time 1983 ms
Memory 85044 KB

Judge Result

Set Name All
Score / Max Score 800 / 800
Status
AC × 68
Set Name Test Cases
All 00_sample00, 00_sample01, 00_sample02, 01_minimal00, 01_minimal01, 01_minimal02, 01_minimal03, 20_small_random00, 20_small_random01, 20_small_random02, 20_small_random03, 20_small_random04, 20_small_random05, 20_small_random06, 20_small_random07, 20_small_random08, 20_small_random09, 20_small_random10, 20_small_random11, 20_small_random12, 20_small_random13, 20_small_random14, 20_small_random15, 20_small_random16, 20_small_random17, 20_small_random18, 20_small_random19, 21_small_increasing00, 21_small_increasing01, 21_small_increasing02, 21_small_increasing03, 21_small_increasing04, 21_small_increasing05, 22_small_decreasing00, 22_small_decreasing01, 22_small_decreasing02, 22_small_decreasing03, 22_small_decreasing04, 22_small_decreasing05, 23_small_mountain00, 23_small_mountain01, 23_small_mountain02, 23_small_mountain03, 23_small_mountain04, 23_small_mountain05, 24_small_valley00, 24_small_valley01, 24_small_valley02, 24_small_valley03, 24_small_valley04, 24_small_valley05, 30_large_random00, 30_large_random01, 30_large_random02, 30_large_random03, 30_large_random04, 31_large_increasing00, 31_large_increasing01, 31_large_increasing02, 32_large_decreasing00, 32_large_decreasing01, 32_large_decreasing02, 33_large_mountain00, 33_large_mountain01, 33_large_mountain02, 34_large_valley00, 34_large_valley01, 34_large_valley02
Case Name Status Exec Time Memory
00_sample00 AC 1 ms 256 KB
00_sample01 AC 1 ms 256 KB
00_sample02 AC 1 ms 256 KB
01_minimal00 AC 1 ms 256 KB
01_minimal01 AC 1 ms 256 KB
01_minimal02 AC 1 ms 256 KB
01_minimal03 AC 1 ms 256 KB
20_small_random00 AC 1 ms 380 KB
20_small_random01 AC 2 ms 380 KB
20_small_random02 AC 1 ms 380 KB
20_small_random03 AC 1 ms 380 KB
20_small_random04 AC 1 ms 380 KB
20_small_random05 AC 1 ms 380 KB
20_small_random06 AC 1 ms 256 KB
20_small_random07 AC 1 ms 256 KB
20_small_random08 AC 1 ms 380 KB
20_small_random09 AC 2 ms 380 KB
20_small_random10 AC 1 ms 380 KB
20_small_random11 AC 1 ms 380 KB
20_small_random12 AC 2 ms 380 KB
20_small_random13 AC 2 ms 380 KB
20_small_random14 AC 1 ms 380 KB
20_small_random15 AC 1 ms 380 KB
20_small_random16 AC 1 ms 380 KB
20_small_random17 AC 1 ms 380 KB
20_small_random18 AC 1 ms 256 KB
20_small_random19 AC 1 ms 324 KB
21_small_increasing00 AC 1 ms 256 KB
21_small_increasing01 AC 1 ms 256 KB
21_small_increasing02 AC 1 ms 380 KB
21_small_increasing03 AC 1 ms 380 KB
21_small_increasing04 AC 1 ms 380 KB
21_small_increasing05 AC 2 ms 380 KB
22_small_decreasing00 AC 1 ms 256 KB
22_small_decreasing01 AC 1 ms 256 KB
22_small_decreasing02 AC 1 ms 380 KB
22_small_decreasing03 AC 1 ms 380 KB
22_small_decreasing04 AC 1 ms 380 KB
22_small_decreasing05 AC 2 ms 380 KB
23_small_mountain00 AC 1 ms 256 KB
23_small_mountain01 AC 1 ms 256 KB
23_small_mountain02 AC 1 ms 380 KB
23_small_mountain03 AC 1 ms 380 KB
23_small_mountain04 AC 1 ms 380 KB
23_small_mountain05 AC 2 ms 380 KB
24_small_valley00 AC 1 ms 256 KB
24_small_valley01 AC 1 ms 256 KB
24_small_valley02 AC 1 ms 380 KB
24_small_valley03 AC 1 ms 380 KB
24_small_valley04 AC 1 ms 380 KB
24_small_valley05 AC 2 ms 380 KB
30_large_random00 AC 865 ms 45108 KB
30_large_random01 AC 499 ms 29876 KB
30_large_random02 AC 32 ms 4532 KB
30_large_random03 AC 82 ms 9012 KB
30_large_random04 AC 605 ms 33972 KB
31_large_increasing00 AC 30 ms 4532 KB
31_large_increasing01 AC 491 ms 45492 KB
31_large_increasing02 AC 992 ms 83508 KB
32_large_decreasing00 AC 29 ms 5172 KB
32_large_decreasing01 AC 885 ms 44980 KB
32_large_decreasing02 AC 1983 ms 85044 KB
33_large_mountain00 AC 30 ms 4660 KB
33_large_mountain01 AC 669 ms 46004 KB
33_large_mountain02 AC 1328 ms 84404 KB
34_large_valley00 AC 30 ms 5300 KB
34_large_valley01 AC 748 ms 44852 KB
34_large_valley02 AC 1669 ms 83508 KB