結果
| 問題 |
No.9 モンスターのレベル上げ
|
| ユーザー |
|
| 提出日時 | 2023-08-14 20:21:52 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 406 ms / 5,000 ms |
| コード長 | 2,422 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 31,488 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-22 21:00:24 |
| 合計ジャッジ時間 | 4,572 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#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[5000];
void init_bheap(void) {
bheap_size = 0;
for (int i = 0; i < 5000; 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 min_heapify(size_t i) {
size_t l, r, m;
l = left(i), r = right(i);
if ((l < bheap_size) && (comp_less(bheap[l], bheap[i])))
m = l;
else
m = i;
if ((r < bheap_size) && (comp_less(bheap[r], bheap[m])))
m = r;
if (m != i) {
Key tmp = bheap[i];
bheap[i] = bheap[m];
bheap[m] = tmp;
min_heapify(m);
}
}
Key pop_bheap(void) {
Key ret = bheap[0];
bheap[0] = bheap[--bheap_size];
min_heapify(0);
return ret;
}
void push_bheap(Key a) {
size_t i, m;
i = bheap_size++;
bheap[i] = a;
while (i > 0 && (comp_less(bheap[i], bheap[m = parent(i)]))) {
Key qt = bheap[i];
bheap[i] = bheap[m];
bheap[m] = qt;
i = m;
}
}
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;
}