結果

問題 No.9 モンスターのレベル上げ
ユーザー magicalkozomagicalkozo
提出日時 2023-09-02 14:52:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 843 ms / 5,000 ms
コード長 2,649 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 30,116 KB
実行使用メモリ 142,548 KB
最終ジャッジ日時 2023-09-02 14:53:07
合計ジャッジ時間 8,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,384 KB
testcase_02 AC 843 ms
142,408 KB
testcase_03 AC 635 ms
112,012 KB
testcase_04 AC 343 ms
62,352 KB
testcase_05 AC 219 ms
42,704 KB
testcase_06 AC 74 ms
16,608 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 99 ms
21,412 KB
testcase_09 AC 811 ms
137,892 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 340 ms
142,536 KB
testcase_12 AC 219 ms
142,516 KB
testcase_13 AC 278 ms
142,548 KB
testcase_14 AC 782 ms
137,824 KB
testcase_15 AC 749 ms
127,232 KB
testcase_16 AC 12 ms
4,412 KB
testcase_17 AC 460 ms
83,772 KB
testcase_18 AC 393 ms
70,892 KB
testcase_19 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

struct Pair {
    int a;
    int b;
};

int f(struct Pair a, struct Pair b) { return a.a == b.a ? a.b < b.b : a.a < b.a; }

typedef struct HeapNode Node;

struct HeapNode {
    Node *left_child;
    Node *next_sibling;
    struct Pair key;
};

void add_child(struct HeapNode *par, struct HeapNode *chi) {
    if (par->left_child == NULL)
        par->left_child = chi;
    else {
        chi->next_sibling = par->left_child;
        par->left_child = chi;
    }
}

int is_empty(struct HeapNode *node) {
    return node == NULL;
}

struct HeapNode *merge(struct HeapNode *A, struct HeapNode *B) {
    if (A == NULL)
        return B;
    if (B == NULL)
        return A;
    if (f(A->key, B->key)) {
        add_child(A, B);
        return A;
    }
    else {
        add_child(B, A);
        return B;
    }
    __builtin_unreachable();
    return NULL;
}

struct Pair top(struct HeapNode *node) {
    return node->key;
}

struct HeapNode *push(struct HeapNode *node, struct Pair key) {
    struct HeapNode *new_node = (struct HeapNode *)malloc(sizeof(struct HeapNode));
    new_node->left_child = NULL;
    new_node->next_sibling = NULL;
    new_node->key = key;
    return merge(node, new_node);
}

struct HeapNode *two_pass_merge(struct HeapNode *node) {
    if (node == NULL || node->next_sibling == NULL)
        return node;
    else {
        struct HeapNode *A, *B, *new_node;
        A = node;
        B = node->next_sibling;
        new_node = node->next_sibling->next_sibling;
        A->next_sibling = NULL;
        B->next_sibling = NULL;
        return merge(merge(A, B), two_pass_merge(new_node));
    }
    __builtin_unreachable();
    return NULL;
}

struct HeapNode *pop(struct HeapNode *node) {
    return two_pass_merge(node->left_child);
}


int main(void) {
    int N; scanf("%d", &N);
    int A[3030], B[3030];
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    for (int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
        B[i + N] = B[i];
    }
    int m = 1073741824;
    for (int i = 0; i < N; i++) {
        struct HeapNode *root;
        for (int j = 0; j < N; j++)
            root = push(root, (struct Pair){A[j], 0});
        for (int j = 0; j < N; j++) {
            struct Pair x = top(root);
            root = pop(root);
            root = push(root, (struct Pair){x.a + B[i + j] / 2, x.b + 1});
        }
        int tmp = 0;
        while (!is_empty(root)) {
            struct Pair x = top(root);
            root = pop(root);
            tmp = tmp > x.b ? tmp : x.b;
        }
        m = m < tmp ? m : tmp;
    }
    printf("%d\n", m);
    return 0;
}
0