結果

問題 No.90 品物の並び替え
ユーザー Masahiro HayashiMasahiro Hayashi
提出日時 2014-12-24 16:40:33
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,611 bytes
コンパイル時間 6,306 ms
コンパイル使用メモリ 111,916 KB
実行使用メモリ 23,916 KB
最終ジャッジ日時 2023-09-02 22:45:13
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
21,708 KB
testcase_01 WA -
testcase_02 AC 69 ms
21,704 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Application
{
    class MainClass
    {
        class Score
        {
            public int Value;
            public int Item1;
            public int Item2;

            public Score(int v, int i1, int i2)
            {
                this.Value = v;
                this.Item1 = i1;
                this.Item2 = i2;
            }
        }

        public static void Main(string[] args)
        {
            var scan = new Scanner();

            var N = scan.NextDigit();
            var M = scan.NextDigit();
            var list = new List<Score>();

            for (var i = 0; i < M; i++)
            {
                var line = scan.NextDigits(3);
                var item1 = line[0];
                var item2 = line[1];
                var score = line[2];

                list.Add(new Score(score, item1, item2));
            }

            var result = computePrice(list, N, M);

            WriteLine(result);
        }

        static int computePrice(List<Score> scores, int N, int M)
        {
            var done = new List<int>();
            var result = 0;

            foreach (var s in scores.OrderBy(x => x.Value).Reverse())
            {
                var added = false;

                if (done.All(x => x != s.Item1))
                {
                    done.Add(s.Item1);
                    added = true;
                }

                if (done.All(x => x != s.Item2))
                {
                    done.Add(s.Item2);
                    added = true;
                }

                if (added) 
                    result += s.Value;

                if (done.Count == N)
                    break;
            }

            return result;
        }

        static void WriteLine(object o)
        {
            System.Console.WriteLine(o.ToString());
        }

        static void WriteEnum<T>(IEnumerable<T> l)
        {
            WriteLine(JoinList(l));
        }

        static string JoinList<T>(IEnumerable<T> l)
        {
            return string.Join(" ", l.Select(x => x.ToString()).ToArray());
        }
    }

    class Scanner
    {
        public int[] NextDigits(int count)
        {
            return Enumerable.Range(0, count)
                .Select(x => NextDigit()).ToArray();
        }

        public string NextToken()
        {
            int i;
            var r = new List<char>();

            while ((i = System.Console.Read()) >= 0)
            {
                var c = Convert.ToChar(i);

                if (IsSpace(c) && r.Count > 0)
                    break;

                r.Add(c);
            }

            return new string(r.ToArray());
        }

        bool IsSpace(char c)
        {
            if (char.IsWhiteSpace(c)) return true;

            return false;
        }

        public int NextDigit()
        {
            var token = NextToken();

            return int.Parse(token);
        }
    }

    class Reader
    {
        public string Item()
        {
            return Items()[0];
        }

        public String[] Items()
        {
            return this.Items(' ');
        }

        public String[] Items(char c)
        {
            return System.Console.ReadLine().Split(c);
        }

        public int Int()
        {
            return Ints(' ')[0];
        }

        public int[] Ints()
        {
            return this.Ints(' ');
        }

        public int[] Ints(char c)
        {
            return Items(c).Select(x => int.Parse(x)).ToArray();
        }
    }
}
0