Submission #1514322


Source Code Expand

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto ans = new int[](N*N);
    foreach (i; 0..N) ans[A[i] - 1] = i + 1;
    
    auto front = N.iota.array;
    auto back = N.iota.map!(i => N - i - 1).array;

    auto pq1 = new BinaryHeap!(Array!(Tuple!(int, int)), "a[0] > b[0]");
    auto pq2 = new BinaryHeap!(Array!(Tuple!(int, int)), "a[0] > b[0]");
    foreach (i; 1..N) pq1.insert(tuple(A[i] - 1, i + 1));
    pq2.insert(tuple(A[0] - 1, 1));

    foreach (i; 0..N*N) {
        if (ans[i] > 0) {
            continue;
        } else if (!pq1.empty) {
            auto t = pq1.front;
            auto pos = t[0];
            auto num = t[1];
            if (pos < i) {
                writeln("No");
                return;
            }
            ans[i] = num;
            front[num-1] -= 1;
            if (front[num-1] == 0) {
                pq1.removeFront;
                pq2.insert(tuple(pos, num));
            }
        } else if (!pq2.empty) {
            auto t = pq2.front;
            auto pos = t[0];
            auto num = t[1];
            if (pos > i) {
                writeln("No");
                return;
            }
            ans[i] = num;
            back[num-1] -= 1;
            if (back[num-1] == 0) pq2.removeFront;
        } else {
            writeln("No");
            return;
        }
    }

    writeln("Yes");
    ans.map!(a => a.to!string).join(" ").writeln;
}

Submission Info

Submission Time
Task D - K-th K
User nebukuro09
Language D (LDC 0.17.0)
Score 0
Code Size 1692 Byte
Status WA
Exec Time 30 ms
Memory 5884 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 2
AC × 24
WA × 25
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
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 30 ms 5500 KB
1_02.txt AC 29 ms 5372 KB
1_03.txt AC 29 ms 5116 KB
1_04.txt AC 29 ms 4860 KB
1_05.txt WA 29 ms 5884 KB
1_06.txt WA 29 ms 4860 KB
1_07.txt WA 29 ms 4988 KB
1_08.txt WA 29 ms 4988 KB
1_09.txt AC 2 ms 3196 KB
1_10.txt AC 2 ms 1276 KB
1_11.txt AC 2 ms 1276 KB
1_12.txt AC 1 ms 2556 KB
1_13.txt AC 2 ms 1276 KB
1_14.txt AC 2 ms 1276 KB
1_15.txt WA 20 ms 4220 KB
1_16.txt AC 2 ms 2940 KB
1_17.txt WA 25 ms 4732 KB
1_18.txt WA 26 ms 4604 KB
1_19.txt WA 27 ms 4860 KB
1_20.txt WA 22 ms 4476 KB
1_21.txt WA 27 ms 5884 KB
1_22.txt WA 24 ms 3708 KB
1_23.txt AC 3 ms 2556 KB
1_24.txt WA 26 ms 4860 KB
1_25.txt WA 21 ms 3324 KB
1_26.txt WA 22 ms 4732 KB
1_27.txt WA 20 ms 4092 KB
1_28.txt AC 2 ms 1276 KB
1_29.txt AC 3 ms 1276 KB
1_30.txt WA 26 ms 3836 KB
1_31.txt WA 28 ms 4476 KB
1_32.txt AC 2 ms 1148 KB
1_33.txt WA 27 ms 5244 KB
1_34.txt AC 1 ms 1276 KB
1_35.txt WA 19 ms 4476 KB
1_36.txt WA 27 ms 5628 KB
1_37.txt WA 25 ms 4220 KB
1_38.txt WA 28 ms 4348 KB
1_39.txt AC 2 ms 2940 KB
1_40.txt WA 12 ms 3964 KB
1_41.txt AC 3 ms 2428 KB
1_42.txt WA 18 ms 2940 KB
1_43.txt WA 26 ms 5500 KB
1_44.txt AC 1 ms 892 KB
1_45.txt AC 2 ms 1148 KB
1_46.txt AC 2 ms 2300 KB