結果

問題 No.771 しおり
ユーザー akakimidoriakakimidori
提出日時 2019-02-08 07:30:30
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 29,372 KB
実行使用メモリ 17,196 KB
最終ジャッジ日時 2023-09-29 12:53:17
合計ジャッジ時間 4,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
17,136 KB
testcase_01 AC 21 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 0 ms
4,380 KB
testcase_25 AC 102 ms
9,248 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 20 ms
4,376 KB
testcase_28 AC 46 ms
5,400 KB
testcase_29 AC 20 ms
4,376 KB
testcase_30 AC 246 ms
17,196 KB
testcase_31 AC 251 ms
17,100 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 236 ms
17,192 KB
testcase_34 AC 233 ms
17,132 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 98 ms
9,204 KB
testcase_41 AC 232 ms
17,184 KB
testcase_42 AC 238 ms
17,156 KB
testcase_43 AC 19 ms
4,380 KB
testcase_44 AC 230 ms
17,156 KB
testcase_45 AC 232 ms
17,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define POS(i,j) ((i)*(1<<n)+(j))

typedef struct book{
  int a,b;
} book;

int calc(int l,int bit,book *p,int n,int *dp){
  if(dp[POS(l,bit)]>0) return dp[POS(l,bit)];
  if(bit==0) return 0;
  int local=2001;
  for(int i=0;i<n;i++){
    if(((bit>>i)&1)==0) continue;
    int v=calc(i,bit^(1<<i),p,n,dp);
    local=MIN(local,MAX(v,p[i].a+(p[l].b-p[l].a)));
  }
  dp[POS(l,bit)]=local;
  return local;
}

void run(void){
  int n;
  scanf("%d",&n);
  book p[18];
  int i;
  for(i=0;i<n;i++) scanf("%d%d",&p[i].a,&p[i].b);
  int *dp=(int *)calloc(n*(1<<n),sizeof(int));
  int ans=2000;
  for(i=0;i<n;i++){
    int v=calc(i,((1<<n)-1)^(1<<i),p,n,dp);
    ans=MIN(ans,v);
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}
0