結果

問題 No.9 モンスターのレベル上げ
ユーザー magicalkozomagicalkozo
提出日時 2023-08-14 19:43:17
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,553 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 32,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 07:45:29
合計ジャッジ時間 4,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 249 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

typedef struct Pair {
    int fst;
    int snd;
} Key;

bool comp_greater(Key a, Key b) {
    return a.fst == b.fst ? a.snd > b.snd : a.fst > b.fst;
}
bool comp_gt(Key a, Key b) {
    return a.fst == b.fst ? a.snd >= b.snd : a.fst >= b.fst;
}
bool comp_less(Key a, Key b) {
    return a.fst == b.fst ? a.snd < b.snd : a.fst < b.fst;
}
bool comp_lt(Key a, Key b) {
    return a.fst == b.fst ? a.snd <= b.snd : a.fst <= b.fst;
}
bool comp_equal(Key a, Key b) {
    return a.fst == b.fst && a.snd == b.snd;
}

size_t bheap_size;
Key bheap[4097];

void init_bheap(void) {
    bheap_size = 0;
    for (int i = 0; i < 4097; i++)
        bheap[i] = (Key){INT_MAX, INT_MAX};
}
#define parent(i) ((i) >> 1)
#define left(i) ((i) << 1)
#define right(i) (((i) << 1) + 1)

void heapify_up(size_t sz) {
    if (sz == 1)
        return;
    Key tmp;
    if (comp_less(bheap[sz], bheap[parent(sz)])) {
        tmp = bheap[sz];
        bheap[sz] = bheap[parent(sz)];
        bheap[parent(sz)] = tmp;
    }
    heapify_up(sz >> 1);
}
void heapify_down(size_t sz) {
    if (right(sz) >= 4097)
        return;
    Key tmp;
    if (comp_gt(bheap[sz], bheap[left(sz)])) {
        tmp = bheap[sz];
        bheap[sz] = bheap[left(sz)];
        bheap[left(sz)] = tmp;
    }
    else if (comp_gt(bheap[sz], bheap[right(sz)])) {
        tmp = bheap[sz];
        bheap[sz] = bheap[right(sz)];
        bheap[right(sz)] = tmp;
    }
    heapify_down(sz << 1);
}
void push_bheap(Key new_key) {
    bheap[++bheap_size] = new_key;
    heapify_up(bheap_size);
}
Key pop_bheap(void) {
    Key ret = bheap[1];
    bheap[1] = bheap[bheap_size--];
    heapify_down(1);
    return ret;
}

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++) {
        init_bheap();
        for (int j = 0; j < N; j++)
            push_bheap((Key){A[j], 0});
        for (int j = 0; j < N; j++) {
            Key x = pop_bheap();
            push_bheap((Key){x.fst + B[i + j] / 2, x.snd + 1});
        }
        int tmp = 0;
        while (bheap_size) {
            Key x = pop_bheap();
            tmp = tmp > x.snd ? tmp : x.snd;
        }
        m = m < tmp ? m : tmp;
    }
    printf("%d\n", m);
    return 0;
}
0