結果
問題 | No.9 モンスターのレベル上げ |
ユーザー |
|
提出日時 | 2023-09-02 14:52:57 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 864 ms / 5,000 ms |
コード長 | 2,649 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 31,360 KB |
実行使用メモリ | 142,464 KB |
最終ジャッジ日時 | 2024-06-11 21:26:10 |
合計ジャッジ時間 | 7,771 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#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;}