結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-03 10:58:53 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 554 ms / 2,000 ms |
| コード長 | 3,630 bytes |
| コンパイル時間 | 7,772 ms |
| コンパイル使用メモリ | 170,564 KB |
| 実行使用メモリ | 207,004 KB |
| 最終ジャッジ日時 | 2025-11-03 10:59:07 |
| 合計ジャッジ時間 | 14,539 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (109 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var n = NN;
var map = NArr(n);
var bitmax = 1 << n;
var dp = new int[bitmax, n, 3];
var ans = 0;
for (var b = 0; b < bitmax; ++b)
{
if (b == 0)
{
for (var i = 0; i < n; ++i)
{
dp[1 << i, i, 0] = map[i][0];
dp[1 << i, i, 1] = map[i][1];
dp[1 << i, i, 2] = map[i][2];
}
}
else
{
for (var i = 0; i < n; ++i)
{
if ((b & (1 << i)) == 0) continue;
for (var j = 0; j < n; ++j)
{
if ((b & (1 << j)) != 0) continue;
var next = b | (1 << j);
if (Math.Min(map[i][1], map[i][2]) >= Math.Min(map[j][1], map[j][2]) && Math.Max(map[i][1], map[i][2]) >= Math.Max(map[j][1], map[j][2])) dp[next, j, 0] = Math.Max(dp[next, j, 0], dp[b, i, 0] + map[j][0]);
if (Math.Min(map[i][1], map[i][2]) >= Math.Min(map[j][0], map[j][2]) && Math.Max(map[i][1], map[i][2]) >= Math.Max(map[j][0], map[j][2])) dp[next, j, 1] = Math.Max(dp[next, j, 1], dp[b, i, 0] + map[j][1]);
if (Math.Min(map[i][1], map[i][2]) >= Math.Min(map[j][0], map[j][1]) && Math.Max(map[i][1], map[i][2]) >= Math.Max(map[j][0], map[j][1])) dp[next, j, 2] = Math.Max(dp[next, j, 2], dp[b, i, 0] + map[j][2]);
if (Math.Min(map[i][0], map[i][2]) >= Math.Min(map[j][1], map[j][2]) && Math.Max(map[i][0], map[i][2]) >= Math.Max(map[j][1], map[j][2])) dp[next, j, 0] = Math.Max(dp[next, j, 0], dp[b, i, 1] + map[j][0]);
if (Math.Min(map[i][0], map[i][2]) >= Math.Min(map[j][0], map[j][2]) && Math.Max(map[i][0], map[i][2]) >= Math.Max(map[j][0], map[j][2])) dp[next, j, 1] = Math.Max(dp[next, j, 1], dp[b, i, 1] + map[j][1]);
if (Math.Min(map[i][0], map[i][2]) >= Math.Min(map[j][0], map[j][1]) && Math.Max(map[i][0], map[i][2]) >= Math.Max(map[j][0], map[j][1])) dp[next, j, 2] = Math.Max(dp[next, j, 2], dp[b, i, 1] + map[j][2]);
if (Math.Min(map[i][0], map[i][1]) >= Math.Min(map[j][1], map[j][2]) && Math.Max(map[i][0], map[i][1]) >= Math.Max(map[j][1], map[j][2])) dp[next, j, 0] = Math.Max(dp[next, j, 0], dp[b, i, 2] + map[j][0]);
if (Math.Min(map[i][0], map[i][1]) >= Math.Min(map[j][0], map[j][2]) && Math.Max(map[i][0], map[i][1]) >= Math.Max(map[j][0], map[j][2])) dp[next, j, 1] = Math.Max(dp[next, j, 1], dp[b, i, 2] + map[j][1]);
if (Math.Min(map[i][0], map[i][1]) >= Math.Min(map[j][0], map[j][1]) && Math.Max(map[i][0], map[i][1]) >= Math.Max(map[j][0], map[j][1])) dp[next, j, 2] = Math.Max(dp[next, j, 2], dp[b, i, 2] + map[j][2]);
}
}
}
for (var i = 0; i < n; ++i)
{
ans = Math.Max(ans, Math.Max(dp[b, i, 0], Math.Max(dp[b, i, 1], dp[b, i, 2])));
}
}
WriteLine(ans);
}
}