結果

問題 No.90 品物の並び替え
ユーザー mbanmban
提出日時 2017-01-08 17:13:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 1,831 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 105,716 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2023-08-22 17:39:09
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
18,724 KB
testcase_01 AC 63 ms
20,716 KB
testcase_02 AC 54 ms
18,720 KB
testcase_03 AC 56 ms
20,724 KB
testcase_04 AC 55 ms
20,860 KB
testcase_05 AC 62 ms
22,740 KB
testcase_06 AC 63 ms
20,864 KB
testcase_07 AC 55 ms
22,792 KB
testcase_08 AC 54 ms
22,728 KB
testcase_09 AC 146 ms
20,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


class Magatro
{
    static int[,] AA;
    static int M,N;
    static int max = 0;
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        N = int.Parse(s[0]);
        M = int.Parse(s[1]);
        AA = new int[N, N];
        for(int i = 0; i < M; i++)
        {
            s = Console.ReadLine().Split(' ');
            AA[int.Parse(s[0]), int.Parse(s[1])] = int.Parse(s[2]);
        }
        int[] S = new int[N];
        for(int i = 0; i < N; i++)
        {
            S[i] = i;
        }
        while (next_permutation(S))
        {
          //  Console.WriteLine(string.Join(" ",S.Select(i=>i.ToString())));
            max = Math.Max(max, Score(S));
        }
        Console.WriteLine(max);
    
    }
    static public bool next_permutation(int[] perm)

    {

        int n = perm.Length;

        int k = -1;

        for (int i = 1; i < n; i++)

            if (perm[i - 1] < perm[i])

                k = i - 1;

        if (k == -1)

        {
            for (int i = 0; i < n; i++)

                perm[i] = i;

            return false;
        }
        int l = k + 1;
        for (int i = l; i < n; i++)
            if (perm[k] < perm[i])
                l = i;
        int t = perm[k];
        perm[k] = perm[l];
        perm[l] = t;
        Array.Reverse(perm, k + 1, perm.Length - (k + 1));

        return true;
    }
    static int Score(int[] items)
    {
        int res = 0;
        for(int i = 0; i < N-1; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                res += AA[items[i], items[j]];
            }
        }
        return res;
    }
}
0