Submission #1059074


Source Code Expand

/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.4.0"
+/

import std.stdio, std.algorithm, std.conv, std.range;
import std.container.rbtree;

// import dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    int n, m, q;
    int[] a;
    sc.read(n, m, q, a);

    bool solve() {
        int[] res;
        bool[] used = new bool[m];
        foreach_reverse (d; a) {
            d--;
            if (used[d]) continue;
            used[d] = true;
            res ~= d;
        }
        res ~= iota(m).filter!(i => !used[i]).array;
        int[] rres = new int[m]; res.each!((i, d) => rres[d] = i.to!int);

        auto tr = redBlackTree!(true)(repeat(0).take(n).array);

        foreach_reverse (d; a) {
            d--;
            int id = rres[d];
//            writeln(tr);
            if (id in tr) {
                tr.removeKey(id);
                tr.insert(id+1);
            } else if (tr.upperBound(id).empty) {
                return false;
            }
        }
//        writeln(tr);
        int r = iota(m).filter!(i => (i==0 || res[i-1] > res[i])).array.back;
        return tr.lowerBound(r).empty;
    }

    if (solve()) {
        writeln("Yes");
    } else {
        writeln("No");
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}

Submission Info

Submission Time
Task E - LRU Puzzle
User yosupo
Language D (LDC 0.17.0)
Score 1200
Code Size 3549 Byte
Status AC
Exec Time 114 ms
Memory 10676 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 4
AC × 76
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.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, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt, 1_70.txt, 1_71.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 256 KB
0_01.txt AC 2 ms 256 KB
0_02.txt AC 2 ms 256 KB
0_03.txt AC 2 ms 256 KB
1_00.txt AC 2 ms 256 KB
1_01.txt AC 2 ms 256 KB
1_02.txt AC 98 ms 10620 KB
1_03.txt AC 98 ms 10620 KB
1_04.txt AC 103 ms 10620 KB
1_05.txt AC 99 ms 10620 KB
1_06.txt AC 111 ms 10556 KB
1_07.txt AC 114 ms 10556 KB
1_08.txt AC 112 ms 10556 KB
1_09.txt AC 110 ms 10556 KB
1_10.txt AC 32 ms 4548 KB
1_11.txt AC 32 ms 4548 KB
1_12.txt AC 32 ms 4548 KB
1_13.txt AC 27 ms 4548 KB
1_14.txt AC 32 ms 4548 KB
1_15.txt AC 32 ms 4548 KB
1_16.txt AC 32 ms 4548 KB
1_17.txt AC 27 ms 4548 KB
1_18.txt AC 33 ms 4668 KB
1_19.txt AC 34 ms 4548 KB
1_20.txt AC 33 ms 4672 KB
1_21.txt AC 34 ms 4924 KB
1_22.txt AC 34 ms 4796 KB
1_23.txt AC 35 ms 4928 KB
1_24.txt AC 34 ms 4804 KB
1_25.txt AC 34 ms 4672 KB
1_26.txt AC 16 ms 2700 KB
1_27.txt AC 14 ms 2676 KB
1_28.txt AC 18 ms 3012 KB
1_29.txt AC 18 ms 3004 KB
1_30.txt AC 18 ms 3672 KB
1_31.txt AC 19 ms 3784 KB
1_32.txt AC 17 ms 3440 KB
1_33.txt AC 21 ms 3904 KB
1_34.txt AC 34 ms 4208 KB
1_35.txt AC 34 ms 4308 KB
1_36.txt AC 33 ms 4092 KB
1_37.txt AC 34 ms 4300 KB
1_38.txt AC 33 ms 4672 KB
1_39.txt AC 33 ms 4672 KB
1_40.txt AC 35 ms 5076 KB
1_41.txt AC 35 ms 5308 KB
1_42.txt AC 16 ms 2748 KB
1_43.txt AC 15 ms 2708 KB
1_44.txt AC 16 ms 2716 KB
1_45.txt AC 16 ms 2732 KB
1_46.txt AC 19 ms 3116 KB
1_47.txt AC 20 ms 3380 KB
1_48.txt AC 19 ms 3388 KB
1_49.txt AC 21 ms 4032 KB
1_50.txt AC 40 ms 3828 KB
1_51.txt AC 43 ms 3756 KB
1_52.txt AC 38 ms 3920 KB
1_53.txt AC 40 ms 3892 KB
1_54.txt AC 42 ms 4728 KB
1_55.txt AC 44 ms 4132 KB
1_56.txt AC 37 ms 5132 KB
1_57.txt AC 43 ms 5056 KB
1_58.txt AC 14 ms 2676 KB
1_59.txt AC 16 ms 2656 KB
1_60.txt AC 15 ms 2656 KB
1_61.txt AC 15 ms 2664 KB
1_62.txt AC 17 ms 3148 KB
1_63.txt AC 17 ms 3964 KB
1_64.txt AC 16 ms 3032 KB
1_65.txt AC 25 ms 4160 KB
1_66.txt AC 82 ms 9340 KB
1_67.txt AC 80 ms 9212 KB
1_68.txt AC 80 ms 9084 KB
1_69.txt AC 82 ms 9340 KB
1_70.txt AC 86 ms 10492 KB
1_71.txt AC 93 ms 10676 KB