結果

問題 No.9 モンスターのレベル上げ
ユーザー magicalkozomagicalkozo
提出日時 2023-08-15 16:18:02
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 2,513 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 33,408 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 03:23:05
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef struct {
    uint64_t fst;
    uint64_t snd;
} Pair;

typedef Pair Key;

int less_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd < b.snd : a.fst < b.fst; }
int lt_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd <= b.snd : a.fst <= b.fst; }
int greater_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd > b.snd : a.fst > b.fst; }
int gt_pair(Pair a, Pair b) { return a.fst == b.fst ? a.snd >= b.snd : a.fst >= b.fst; }
int equal_pair(Pair a, Pair b) { return a.fst == b.fst && a.snd == b.snd; }

typedef struct SkewNode {
    Key key;
    struct SkewNode *left;
    struct SkewNode *right;
} SNode, *SHeap;

void swap_snode(SNode *x, SNode *y) {
    SNode tmp = *x;
    *x = *y;
    *y = tmp;
}
int top_sheap(SHeap h, Key *k) {
    if (h == NULL)
		return -1;
	*k = h->key;
	return 0;
}
SNode* merge_sheap(SHeap x, SHeap y) {
    if (x == NULL)
		return y;
	if (y == NULL)
		return x;
	if (greater_pair(x->key, y->key))
		swap_snode(x, y);
	SNode *tmp = merge_sheap(x->right, y);
	x->right = x->left;
	x->left  = tmp;
	return x;
}
SNode* push_sheap(SHeap h, Key k) {
    SNode *node;
	if ((node = (SNode *)malloc(sizeof(SNode))) == NULL)
		return h;
	node->key = k;
	node->left = node->right = NULL;
    return merge_sheap(h, node);
}
SNode* pop_sheap(SHeap h) {
    SNode *l = h->left;
    SNode *r = h->right;
    free(h);
    return merge_sheap(l, r);
}
void free_sheap(SHeap h) {
    if (h == NULL)
		return;
	if (h->left != NULL)
		free_sheap(h->left);
	if (h->right != NULL)
		free_sheap(h->right);
	free(h);
}

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++) {
        SHeap heap;
        int heap_size = 0;
        for (int j = 0; j < N; j++) {
            heap = push_sheap(heap, (Key){A[j], 0});
            heap_size++;
        }
        for (int j = 0; j < N; j++) {
            SNode* x = pop_sheap(heap);
            heap = push_sheap(heap, (Key){x->key.fst + B[i + j] / 2, x->key.snd + 1});
        }
        int tmp = 0;
        while (heap_size) {
            SNode* x = pop_sheap(heap);
            tmp = tmp > x->key.snd ? tmp : x->key.snd;
            heap_size--;
        }
        m = m < tmp ? m : tmp;
        free_sheap(heap);
    }
    printf("%d\n", m);
    return 0;
}
0