結果

問題 No.90 品物の並び替え
ユーザー mori_chibimori_chibi
提出日時 2017-09-04 16:46:13
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,140 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 110,208 KB
実行使用メモリ 53,504 KB
最終ジャッジ日時 2024-04-24 12:48:39
合計ジャッジ時間 9,462 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
53,504 KB
testcase_01 AC 550 ms
23,552 KB
testcase_02 AC 31 ms
19,328 KB
testcase_03 AC 78 ms
23,424 KB
testcase_04 AC 82 ms
23,296 KB
testcase_05 AC 584 ms
23,552 KB
testcase_06 AC 552 ms
23,432 KB
testcase_07 AC 38 ms
23,296 KB
testcase_08 AC 29 ms
19,328 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace SortItems
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] P = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int R = MainProcess(P[0],P[1]);
            Console.WriteLine(R);
        }

        private static int MainProcess(int N, int M)
        {
            int[][] itemlines = new int[M][];
            for(int i = 0; i < M; i++)
            {
                itemlines[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            }
            int[] items = new int[N];
            for(int i = 0; i < N; i++)
            {
                items[i] = i;
            }
            int R = 0;
            var perm = new Permutation();
            foreach (var n in perm.Enumerate(items))
            {
                int S = 0, idx0 = 0, idx1 = 0;
                for (int i = 0; i < M; i++)
                {
                    for(int j = 0;j < N; j++)
                    {
                        if (itemlines[i][0] == n[j]) idx0 = j;
                        if (itemlines[i][1] == n[j]) idx1 = j;
                    }
                    if(idx0 < idx1)
                    {
                        S += itemlines[i][2];
                    }
                }
                R = Math.Max(R, S);
            }
            return R;
        }
    }
    /*
    * Copy from http://qiita.com/gushwell/items/8780fc2b71f2182f36ac
    */
    public class Permutation
    {
        public IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items)
        {
            if (items.Count() == 1)
            {
                yield return new T[] { items.First() };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };
                var unused = items.Except(leftside);
                foreach (var rightside in Enumerate(unused))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }
}
0