結果
問題 |
No.1045 直方体大学
|
ユーザー |
![]() |
提出日時 | 2020-05-01 23:22:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,562 bytes |
コンパイル時間 | 763 ms |
コンパイル使用メモリ | 84,016 KB |
実行使用メモリ | 27,844 KB |
最終ジャッジ日時 | 2024-12-25 14:32:07 |
合計ジャッジ時間 | 1,932 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 2 WA * 15 |
ソースコード
#include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <cassert> #include <numeric> #include <functional> #include <cassert> //#include <numeric> #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; ll dp[1 << 16][16][3]; void solve() { int n; scanf("%d", &n); vector<int> a(n * 3); int i,j,k; for (i = 0; i < n; i++) { scanf("%d%d%d", &a[3*i], &a[3*i+1], &a[3*i+2]); } for (i = 0; i < (1 << n); i++) { for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { dp[i][j][k] = -1; } } } ll ans = 0; for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { dp[1 << j][j][k] = a[3 * j + k]; ans = MAX(ans, dp[1 << j][j][k]); } } for (i = 0; i < (1 << n); i++) { for (j = 0; j < n; j++) { for (k = 0; k < 3; k++) { if (dp[i][j][k] >= 0) { int p; for (p = 0; p < n; p++) { if (i & (1 << p)) continue; int k2; for (k2 = 0; k2 < 3; k2++) { int k_1 = (k + 1) % 3, k_2 = (k + 2) % 3; int k2_1 = (k2 + 1) % 3, k2_2 = (k2 + 2) % 3; if (MIN(3 * j + k_1, 3 * j + k_2) <= MIN(3 * p + k2_1, 3 * p + k2_2)) { if (MAX(3 * j + k_1, 3 * j + k_2) <= MAX(3 * p + k2_1, 3 * p + k2_2)) { dp[i | (1 << p)][p][k2] = dp[i][j][k] + a[3 * p + k2]; ans = MAX(ans, dp[i | (1 << p)][p][k2]); } } } } } } } } printf("%lld\n", ans); return; } int main(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t<T; t++) { //printf("Case #%d: ", t+1); solve(); } #endif return 0; }