結果

問題 No.9 モンスターのレベル上げ
ユーザー mudbdbmudbdb
提出日時 2015-06-21 22:28:31
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4,394 ms / 5,000 ms
コード長 2,037 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 26,204 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 03:52:23
合計ジャッジ時間 21,372 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2,320 ms
4,376 KB
testcase_03 AC 1,594 ms
4,380 KB
testcase_04 AC 648 ms
4,376 KB
testcase_05 AC 355 ms
4,376 KB
testcase_06 AC 79 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 125 ms
4,376 KB
testcase_09 AC 2,128 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4,394 ms
4,376 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 2,525 ms
4,380 KB
testcase_14 AC 2,160 ms
4,376 KB
testcase_15 AC 1,939 ms
4,376 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 998 ms
4,376 KB
testcase_18 AC 792 ms
4,380 KB
testcase_19 AC 4 ms
4,376 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;
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 max_count()
{
  int max = 0;
  int cnt;
  int mask = (1 << Base)-1;
  struct mon *l;
  for (l=ListPool; l<ListEnd; l++) {
    cnt = l->level & mask;
    if (max < cnt) {
      max = cnt;
    }
  }
  return max;
}
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;
  }

  int i;
  int min = N+1;
  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);
      list_in(a);
    }
    for (Bp=B; Bp<Bstart; Bp++) {
      a = list_out();
      a->level += ((*Bp)+1);
      list_in(a);
    }
    int cnt = max_count();
    if (cnt < min) {
      min = cnt;
    }
    list_init(N, A);
  }

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