結果

問題 No.90 品物の並び替え
ユーザー _matumo__matumo_
提出日時 2018-07-04 19:40:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,205 ms / 5,000 ms
コード長 1,503 bytes
コンパイル時間 2,798 ms
コンパイル使用メモリ 104,928 KB
実行使用メモリ 45,884 KB
最終ジャッジ日時 2023-09-13 17:34:56
合計ジャッジ時間 6,403 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
22,104 KB
testcase_01 AC 227 ms
30,392 KB
testcase_02 AC 68 ms
24,072 KB
testcase_03 AC 79 ms
23,948 KB
testcase_04 AC 85 ms
24,180 KB
testcase_05 AC 247 ms
28,320 KB
testcase_06 AC 202 ms
28,428 KB
testcase_07 AC 69 ms
24,076 KB
testcase_08 AC 67 ms
21,940 KB
testcase_09 AC 2,205 ms
45,884 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.Generic;
using System.Linq;
using System.Text;

namespace YukiCoder
{
    class Program
    {
        static IEnumerable<string> Permu(string str)
        {
            if (str.Length == 1) yield return str;
            char[] pa = str.ToCharArray();
            for (int i = 0; i < pa.Length; i++)
            {
                char c = pa[i]; pa[i] = pa[0]; pa[0] = c;
                foreach (var s in Permu(new string(pa, 1, pa.Length - 1)))
                {
                    yield return c + s;
                }
            }
        }
        static void Main(string[] args)
        {
            var va = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[][] pia = new int[va[1]][];
            for (int i = 0; i < va[1]; i++)
            {
                pia[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }
            var vb = Enumerable.Range(0, va[0]).Select(n => (char)(n + '0')).ToArray();
            int sMax = 0;
            Permu(new string(vb)).ToList().ForEach(s =>
            {
                int sum = 0;
                for(int i=0; i<pia.Count(); i++)
                {
                    int na = s.IndexOf((char)(pia[i][0] + '0'));
                    int nb = s.IndexOf((char)(pia[i][1] + '0'));
                    if (na < nb) sum += pia[i][2];
                }
                if (sum > sMax) sMax = sum;
            });
            Console.WriteLine(sMax);
        }
    }
}
0