結果
| 問題 |
No.9 モンスターのレベル上げ
|
| ユーザー |
|
| 提出日時 | 2023-08-15 16:18:02 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,513 bytes |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 33,024 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 00:07:25 |
| 合計ジャッジ時間 | 3,491 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 20 |
ソースコード
#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;
}