結果

問題 No.1045 直方体大学
ユーザー motmot
提出日時 2020-08-02 16:14:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,331 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 83,372 KB
実行使用メモリ 18,884 KB
最終ジャッジ日時 2023-09-25 20:13:16
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 427 ms
18,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int N;
int A[3][20];
int DP[(1<<18)][20][3];

int solve(int S, int x, int k) {
  if(DP[S][x][k]>0) return DP[S][x][k];
  if(S==0) {
    DP[S][x][k] = A[k][x];
  }
  int tmp1, tmp2, tmp3, tmp4;
  for(int i=0;i<N;++i) {
    if((S&(1<<i))==0) continue;
    for(int j=0;j<3;++j) {
      tmp1 = max(A[(k+1)%3][x], A[(k+2)%3][x]);
      tmp2 = min(A[(k+1)%3][x], A[(k+2)%3][x]);
      tmp3 = max(A[(j+1)%3][i], A[(j+2)%3][i]);
      tmp4 = min(A[(j+1)%3][i], A[(j+2)%3][i]);
      if(tmp1>tmp3 || tmp2>tmp4) continue;
      else DP[S][x][k] = max(DP[S][x][k], solve(S^(1<<i), i, j)+A[k][x]);
    }
  }
  return DP[S][x][k];
}

int main() {
  cin>>N;
  for(int i=0;i<N;++i) cin>>A[0][i]>>A[1][i]>>A[2][i];
  int ans = 0;
  int S = (1<<N) - 1;
  for(int i=0;i<N;++i) {
    for(int j=0;j<3;++j) {
      ans = max(ans, solve(S^(1<<i), i, j));
    }
  }
  cout<<ans<<endl;
}
0