結果

問題 No.90 品物の並び替え
ユーザー AreTrashAreTrash
提出日時 2016-04-14 09:58:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 4,540 ms / 5,000 ms
コード長 1,709 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 111,340 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-04-15 01:21:52
合計ジャッジ時間 7,226 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
18,944 KB
testcase_01 AC 349 ms
23,296 KB
testcase_02 AC 28 ms
19,200 KB
testcase_03 AC 56 ms
23,168 KB
testcase_04 AC 61 ms
23,168 KB
testcase_05 AC 389 ms
23,424 KB
testcase_06 AC 302 ms
23,040 KB
testcase_07 AC 35 ms
20,736 KB
testcase_08 AC 29 ms
19,328 KB
testcase_09 AC 4,540 ms
23,424 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;

namespace No90_1{
    public class Program{
        public static void Main(string[] args){
            var input = ReadList(Convert.ToInt32);
            var n = input[0];
            var m = input[1];

            var score = new List<List<int>>();
            for(var i = 0; i < m; i++){
                score.Add(ReadList(Convert.ToInt32));
            }

            var stack = new Stack<int>();
            var max = 0;

            Action<int> act = null;
            act = cnt =>{
                for(var i = 0; i < n; i++) {
                    if(!stack.Contains(i)) {
                        stack.Push(i);
                    } else {
                        continue;
                    }
                    act(cnt + 1);
                    stack.Pop();
                }

                if(cnt == n){
                    var tmpList = score.ToList();
                    var point = 0;
                    foreach(var s in stack){
                        point += tmpList.Where(item => item[0] == s).Sum(item => item[2]);
                        tmpList.RemoveAll(item => item[0] == s || item[1] == s);
                    }
                    max = Math.Max(max, point);
                }
            };
            act(0);

            Console.WriteLine(max);
        }

        public static TOutput Read<TOutput>(Converter<string, TOutput> converter){
            return converter(Console.ReadLine());
        }

        public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' '){
            return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter);
        }
    }
}
0