結果

問題 No.1045 直方体大学
ユーザー butsurizukibutsurizuki
提出日時 2020-05-27 04:03:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 33,408 KB
実行使用メモリ 18,268 KB
最終ジャッジ日時 2024-04-21 05:04:10
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
18,116 KB
testcase_01 AC 6 ms
18,188 KB
testcase_02 AC 6 ms
18,160 KB
testcase_03 AC 5 ms
18,068 KB
testcase_04 AC 5 ms
18,176 KB
testcase_05 AC 6 ms
18,176 KB
testcase_06 AC 7 ms
18,216 KB
testcase_07 AC 6 ms
18,192 KB
testcase_08 AC 20 ms
18,184 KB
testcase_09 AC 15 ms
18,044 KB
testcase_10 AC 16 ms
18,224 KB
testcase_11 AC 17 ms
18,196 KB
testcase_12 AC 23 ms
18,268 KB
testcase_13 AC 22 ms
18,196 KB
testcase_14 AC 17 ms
18,176 KB
testcase_15 AC 25 ms
18,216 KB
testcase_16 AC 34 ms
18,212 KB
testcase_17 AC 7 ms
18,056 KB
testcase_18 AC 138 ms
18,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define size 65536

int max(int a,int b){if(a>b){return a;}return b;}

bool stfl(int ba,int bb,int ta,int tb){
  if(ba<=ta && bb<=tb){return true;}
  if(ba<=tb && bb<=ta){return true;}
  return false;
}

int ep[4][2]={
  {1,2},
  {0,2},
  {0,1}
};

int main(void){
  int i,j,n,m,k,h,w,r=0,t;
  int l[16][4];
  int dp[size][16][4];
  int nb,nd;
  for(i=0;i<size;i++){
    for(j=0;j<16;j++){
      for(k=0;k<4;k++){
        dp[i][j][k]=-inf;
      }
    }
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      scanf("%d",&l[i][j]);
      dp[(1<<i)][i][j]=l[i][j];
    }
  }

  for(i=0;i<(1<<n);i++){
    for(j=0;j<n;j++){
      for(k=0;k<3;k++){
        if(dp[i][j][k]<0){continue;}
        r=max(dp[i][j][k],r);

        for(nb=0;nb<n;nb++){
          if(i&(1<<nb)){continue;}
          for(nd=0;nd<3;nd++){
            if(stfl(l[j][ep[k][0]],l[j][ep[k][1]],l[nb][ep[nd][0]],l[nb][ep[nd][1]])){
              dp[i|(1<<nb)][nb][nd]=max(dp[i][j][k]+l[nb][nd],dp[i|(1<<nb)][nb][nd]);
            }
          }
        }

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