結果

問題 No.1045 直方体大学
ユーザー motmot
提出日時 2020-08-02 16:15:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,316 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 84,124 KB
実行使用メモリ 31,008 KB
最終ジャッジ日時 2023-09-25 20:15:23
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 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,376 KB
testcase_18 AC 473 ms
31,008 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);

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

ll solve(ll S, ll x, ll k) {
  if(DP[S][x][k]>0) return DP[S][x][k];
  if(S==0) {
    DP[S][x][k] = A[k][x];
  }
  ll tmp1, tmp2, tmp3, tmp4;
  for(ll i=0;i<N;++i) {
    if((S&(1<<i))==0) continue;
    for(ll 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(ll i=0;i<N;++i) cin>>A[0][i]>>A[1][i]>>A[2][i];
  ll ans = 0;
  ll S = (1<<N) - 1;
  for(ll i=0;i<N;++i) {
    for(ll j=0;j<3;++j) {
      ans = max(ans, solve(S^(1<<i), i, j));
    }
  }
  cout<<ans<<endl;
}
0