結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
259_Momone
|
| 提出日時 | 2020-05-01 22:31:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,346 bytes |
| コンパイル時間 | 2,304 ms |
| コンパイル使用メモリ | 210,468 KB |
| 最終ジャッジ日時 | 2025-01-10 05:11:15 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 17 |
ソースコード
#include<bits/stdc++.h>
int main(){
using namespace std;
unsigned long N;
cin >> N;
vector<pair<pair<unsigned long, unsigned long>, unsigned long>> r(N);
for(auto&& i : r){
vector v{0, 0, 0};
cin >> v[0] >> v[1] >> v[2];
sort(v.begin(), v.end());
i.first.first = v[0];
i.first.second = v[1];
i.second = v[2];
}
unsigned long ans{0};
vector<unordered_map<unsigned long, unsigned long>> dp(1UL << N);
for(unsigned long i{0}; i < N; ++i){
ans = max(ans, r[i].second);
dp[1UL << i].emplace(r[i].first.second * 1048576 + r[i].first.first, r[i].second);
dp[1UL << i].emplace(r[i].first.first * 1048576 + r[i].first.second, r[i].second);
dp[1UL << i].emplace(r[i].second * 1048576 + r[i].first.first, r[i].first.second);
dp[1UL << i].emplace(r[i].first.first * 1048576 + r[i].second, r[i].first.second);
dp[1UL << i].emplace(r[i].second * 1048576 + r[i].first.second, r[i].first.first);
dp[1UL << i].emplace(r[i].first.second * 1048576 + r[i].second, r[i].first.first);
}
const auto& chmax = [&ans](unsigned long& x, unsigned long a) -> unsigned long { return x = max(x, ans = max(ans, a)); };
for(unsigned long j{1}; j < 1UL << N; ++j)for(const auto& [s, h] : dp[j])for(unsigned long i{0}; i < N; ++i)if(!((j >> i) & 1)){
unsigned long c{1UL << i};
const auto& [x, y] = make_pair(s / 1048576, s % 1048576);
if(r[i].first.second <= x && r[i].first.first <= y)chmax(dp[j | c][r[i].first.second * 1048576 + r[i].first.first], h + r[i].second);
if(r[i].first.first <= x && r[i].first.second <= y)chmax(dp[j | c][r[i].first.first * 1048576 + r[i].first.second], h + r[i].second);
if(r[i].second <= x && r[i].first.first <= y)chmax(dp[j | c][r[i].second * 1048576 + r[i].first.first], h + r[i].first.second);
if(r[i].first.first <= x && r[i].second <= y)chmax(dp[j | c][r[i].first.first * 1048576 + r[i].second], h + r[i].first.second);
if(r[i].second <= x && r[i].first.second <= y)chmax(dp[j | c][r[i].second * 1048576 + r[i].first.second], h + r[i].first.first);
if(r[i].first.second <= x && r[i].second <= y)chmax(dp[j | c][r[i].first.second * 1048576 + r[i].second], h + r[i].first.first);
}
cout << ans << endl;
return 0;
}
259_Momone