結果
問題 | No.90 品物の並び替え |
ユーザー |
|
提出日時 | 2023-10-21 23:26:13 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 378 ms / 5,000 ms |
コード長 | 1,678 bytes |
コンパイル時間 | 15,062 ms |
コンパイル使用メモリ | 166,644 KB |
実行使用メモリ | 187,276 KB |
最終ジャッジ日時 | 2024-09-22 00:55:15 |
合計ジャッジ時間 | 16,646 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (99 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) 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;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 c = NList;var (n, m) = (c[0], c[1]);var map = NArr(m);var pts = new int[n, n];foreach (var list in map){pts[list[0], list[1]] = list[2];}var ans = 0;Permutate(n, list =>{var sub = 0;for (var i = 0; i < list.Length; ++i) for (var j = i + 1; j < list.Length; ++j){sub += pts[list[i], list[j]];}ans = Math.Max(ans, sub);});WriteLine(ans);}static void Permutate(int n, Action<int[]> action){var seed = new int[n];for (var i = 0; i < n; ++i) seed[i] = i;var used = new bool[n];var perm = new int[n];Permutate(0, seed, perm, used, action);}static void Permutate(int pos, int[] seed, int[] perm, bool[] used, Action<int[]> action){if (pos == used.Length) action(perm);for (var i = 0; i < used.Length; ++i){if (used[i]) continue;perm[pos] = seed[i];used[i] = true;Permutate(pos + 1, seed, perm, used, action);used[i] = false;}}}