結果

問題 No.90 品物の並び替え
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-21 23:26:13
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 232 ms / 5,000 ms
コード長 1,678 bytes
コンパイル時間 14,974 ms
コンパイル使用メモリ 158,400 KB
実行使用メモリ 177,884 KB
最終ジャッジ日時 2023-10-21 23:26:31
合計ジャッジ時間 17,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
32,368 KB
testcase_01 AC 97 ms
32,412 KB
testcase_02 AC 82 ms
32,380 KB
testcase_03 AC 84 ms
32,380 KB
testcase_04 AC 84 ms
32,420 KB
testcase_05 AC 97 ms
32,420 KB
testcase_06 AC 97 ms
32,380 KB
testcase_07 AC 84 ms
32,380 KB
testcase_08 AC 83 ms
32,380 KB
testcase_09 AC 232 ms
177,884 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (110 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

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;
        }
    }
}
0