結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2020-05-01 22:19:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 328 ms / 2,000 ms |
| コード長 | 2,502 bytes |
| コンパイル時間 | 1,951 ms |
| コンパイル使用メモリ | 174,296 KB |
| 実行使用メモリ | 81,792 KB |
| 最終ジャッジ日時 | 2024-12-25 12:32:21 |
| 合計ジャッジ時間 | 6,873 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;
int dp[1<<17][17][3][3];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N;cin>>N;
vector<vector<int>> S(17,vector<int>(3));
S[0][0]=INF;
S[0][1]=INF;
S[0][2]=INF;
for(int i=0;i<N;i++){
for(int j=0;j<3;j++){
cin>>S[i+1][j];
}
}
for(int bit=0;bit<(1<<17);bit++){
for(int i=0;i<17;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
dp[bit][i][j][k]=-INF;
dp[1][0][j][k]=0;
}
}
}
}
for(int bit=0;bit<(1<<17);bit++){
for(int i=0;i<17;i++){
if(!(bit&(1<<i))) continue;
for(int j=0;j<3;j++){
for(int k=j+1;k<3;k++){
if(dp[bit][i][j][k]<0) continue;
for(int to=1;to<17;to++){
if(bit&(1<<to)) continue;
for(int toj=0;toj<3;toj++){
for(int tok=toj+1;tok<3;tok++){
int a=S[i][j],b=S[i][k],c=S[i][(3-j-k)];
if(a>b) swap(a,b);
int d=S[to][toj],e=S[to][tok],f=S[to][3-toj-tok];
if(d>e) swap(d,e);
if(a>=d&&b>=e){
chmax(dp[bit|(1<<to)][to][toj][tok],dp[bit][i][j][k]+f);
}
}
}
}
}
}
}
}
int ans=-INF;
for(int bit=0;bit<(1<<17);bit++){
for(int i=0;i<17;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
chmax(ans,dp[bit][i][j][k]);
}
}
}
}
cout<<ans<<endl;
}
Rubikun