結果

問題 No.9 モンスターのレベル上げ
ユーザー mudbdbmudbdb
提出日時 2015-06-22 02:34:00
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1,887 ms / 5,000 ms
コード長 2,068 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 26,640 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 03:52:35
合計ジャッジ時間 7,738 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 872 ms
4,376 KB
testcase_03 AC 305 ms
4,380 KB
testcase_04 AC 250 ms
4,376 KB
testcase_05 AC 155 ms
4,380 KB
testcase_06 AC 31 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 40 ms
4,376 KB
testcase_09 AC 698 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1,887 ms
4,376 KB
testcase_12 AC 9 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 719 ms
4,380 KB
testcase_15 AC 778 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 430 ms
4,380 KB
testcase_18 AC 333 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
struct mon {
  struct mon* next;
  int level;
};
int cmp(const void* a, const void* b)
{
  return (*(int*)a - *(int*)b);
}
int Base = 11;
int Mask = 0;
struct mon *List = 0;
struct mon *ListPool = 0;
struct mon *ListEnd = 0;
void list_init(int N, int *A)
{
  if (ListPool == 0) {
    qsort(A, N, sizeof(int), cmp);
    ListPool = (struct mon*)malloc(sizeof(struct mon)*N);
    ListEnd = ListPool+N;
  }
  List = ListPool;
  struct mon *l;
  for (l=List; l<ListEnd; l++, A++) {
    l->next = l+1;
    l->level = *A;
  }
  List[N-1].next = 0;
  return;
}
struct mon *list_out(void)
{
  struct mon *a = List;
  List = a->next;
  a->next = 0;
  return a;
}
void list_in(struct mon *a)
{
  struct mon *l1 = 0;
  struct mon *l = List;
  while (l!=0) {
    if (a->level <= l->level) {
      break;
    } else {
      l1 = l;
    }
    l = l->next;
  }
  if (l1 == 0) {
    a->next = List;
    List = a;
  } else {
    a->next = l1->next;
    l1->next = a;
  }
  return;
}
int main()
{
  int N;
  scanf("%d", &N);
  int *A = (int*)malloc(sizeof(int)*N*2);
  int *B = A+N;
  int *Ap;
  int *Aend = A+N;
  int *Bp;
  int *Bend = B+N;
  for (Ap=A; Ap<Aend; Ap++) scanf("%d", Ap);
  for (Bp=B; Bp<Bend; Bp++) scanf("%d", Bp);

  for (Ap=A; Ap<Aend; Ap++) (*Ap) <<= Base;
  for (Bp=B; Bp<Bend; Bp++) {
    (*Bp) >>= 1;
    (*Bp) <<= Base;
  }

  Mask = (1 << Base)-1;
  int i;
  int min = N+1;
  int max = 0;
  int cnt;
  struct mon *a;
  list_init(N, A);
  for (i=0; i<N; i++) {
    int *Bstart = B+i;
    for (Bp=Bstart; Bp<Bend; Bp++) {
      a = list_out();
      a->level += ((*Bp)+1);
      cnt = a->level & Mask;
      list_in(a);
      if (max < cnt) max = cnt;
      if (min <= max) goto NEXT;
    }
    for (Bp=B; Bp<Bstart; Bp++) {
      a = list_out();
      a->level += ((*Bp)+1);
      cnt = a->level & Mask;
      list_in(a);
      if (max < cnt) max = cnt;
      if (min <= max) goto NEXT;
    }
    if (max < min) {
      min = max;
    }
    NEXT:
    max = 0;
    list_init(N, A);
  }

  printf("%d\n", min);
  return 0;
}
0