Submission #1353923


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, core.stdc.stdio;

immutable int INF = 10^^9 + 2;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int ans = -1;

    foreach (k; 0..N+10) {
        auto B = new int[](N + k);
        fill(B, -INF);
        foreach (i; 0..N) B[i + k] = A[i];
        if (B.length % 2 == 0) B ~= 10^^9 + 1;
        auto M = B.length.to!int;

        bool[int] used;
        foreach (a; A) used[a] = true;

        foreach (i; iota(M-1, 0, -2)) {
            int x = min(B[i], B[i-1]) - 1;
            if (B[i/2-1] != -INF) continue;
            while (x in used) x--;
            used[x] = true;
            B[i/2-1] = x;
        }

        bool ok = true;
        foreach (i; 0..M) {
            if (B[i] < 0) ok = false;
            if (i * 2 + 1 < M && B[i] >= B[i * 2 + 1]) ok = false;
            if (i * 2 + 2 < M && B[i] >= B[i * 2 + 2]) ok = false;
        }

        if (ok) {
            ans = N + k;
            break;
        }
    }

    ans.writeln;
}

Submission Info

Submission Time
Task D - 壊れかけのヒープ
User nebukuro09
Language D (LDC 0.17.0)
Score 0
Code Size 1222 Byte
Status WA
Exec Time 4 ms
Memory 3324 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 27
WA × 6
Set Name Test Cases
All hard-01, hard-02, hard-03, hard-04, hard-05, hard-06, hard-07, hard-08, hard-09, hard-10, hard-11, hard-12, hard-corner-01, hard-corner-02, hard-corner-03, hard-corner-04, hard-corner-05, hard-random-01, hard-random-02, hard-random-03, hard-random-04, hard-random-05, hard-random-06, hard-semirandom-01, hard-semirandom-02, hard-semirandom-03, hard-semirandom-04, hard-semirandom-05, hard-semirandom-06, sample-01, sample-02, sample-03, sample-04
Case Name Status Exec Time Memory
hard-01 AC 1 ms 256 KB
hard-02 WA 1 ms 256 KB
hard-03 AC 1 ms 256 KB
hard-04 AC 2 ms 508 KB
hard-05 AC 1 ms 256 KB
hard-06 AC 1 ms 256 KB
hard-07 AC 1 ms 256 KB
hard-08 AC 1 ms 256 KB
hard-09 AC 1 ms 380 KB
hard-10 AC 1 ms 380 KB
hard-11 AC 1 ms 380 KB
hard-12 AC 1 ms 256 KB
hard-corner-01 WA 1 ms 256 KB
hard-corner-02 WA 1 ms 256 KB
hard-corner-03 WA 1 ms 380 KB
hard-corner-04 WA 2 ms 508 KB
hard-corner-05 WA 3 ms 1404 KB
hard-random-01 AC 1 ms 256 KB
hard-random-02 AC 1 ms 256 KB
hard-random-03 AC 1 ms 256 KB
hard-random-04 AC 4 ms 1276 KB
hard-random-05 AC 3 ms 1404 KB
hard-random-06 AC 3 ms 3068 KB
hard-semirandom-01 AC 1 ms 256 KB
hard-semirandom-02 AC 1 ms 256 KB
hard-semirandom-03 AC 1 ms 256 KB
hard-semirandom-04 AC 4 ms 1276 KB
hard-semirandom-05 AC 3 ms 1404 KB
hard-semirandom-06 AC 3 ms 3324 KB
sample-01 AC 1 ms 256 KB
sample-02 AC 1 ms 256 KB
sample-03 AC 1 ms 256 KB
sample-04 AC 1 ms 256 KB