結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-01 22:06:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 886 ms / 2,000 ms |
| コード長 | 1,470 bytes |
| コンパイル時間 | 2,526 ms |
| コンパイル使用メモリ | 200,148 KB |
| 最終ジャッジ日時 | 2025-01-10 04:54:06 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | int n; scanf("%d", &n); auto a = make_v<int>(3, n);
| ~~~~~^~~~~~~~~~
main.cpp:19:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | for(int i = 0; i < n; i++) scanf("%d%d%d", &a[0][i], &a[1][i], &a[2][i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;
template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
int main() {
int n; scanf("%d", &n); auto a = make_v<int>(3, n);
for(int i = 0; i < n; i++) scanf("%d%d%d", &a[0][i], &a[1][i], &a[2][i]);
int ans = 0;
auto dp = make_v<int>(1 << n, n, 6);
std::vector<int> A = {0, 0, 1, 1, 2, 2};
std::vector<int> B = {1, 2, 0, 2, 0, 1};
std::vector<int> C = {2, 1, 2, 0, 1, 0};
for(int j = 0; j < n; j++) {
for(int k = 0; k < 6; k++) {
int x = a[A[k]][j], y = a[B[k]][j], z = a[C[k]][j];
dp[1 << j][j][k] = z;
ans = std::max(ans, z);
}
}
for(int i = 0; i < (1 << n); i++) {
for(int j = 0; j < n; j++) {
if(!(i >> j & 1)) continue;
for(int k = 0; k < 6; k++) {
int x = a[A[k]][j], y = a[B[k]][j], z = a[C[k]][j];
for(int l = 0; l < n; l++) {
if(i >> l & 1) continue;
for(int K = 0; K < 6; K++) {
int X = a[A[K]][l], Y = a[B[K]][l], Z = a[C[K]][l];
if(x < X or y < Y) continue;
dp[i | (1 << l)][l][K] = std::max(dp[i | (1 << l)][l][K], dp[i][j][k] + Z);
ans = std::max(ans, dp[i | (1 << l)][l][K]);
}
}
}
}
}
printf("%d\n", ans);
return 0;
}