結果

問題 No.90 品物の並び替え
ユーザー 14番14番
提出日時 2016-03-29 16:29:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,594 ms / 5,000 ms
コード長 3,159 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 115,380 KB
実行使用メモリ 88,800 KB
最終ジャッジ日時 2024-04-10 05:50:41
合計ジャッジ時間 4,877 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,208 KB
testcase_01 AC 206 ms
36,756 KB
testcase_02 AC 28 ms
24,204 KB
testcase_03 AC 40 ms
26,388 KB
testcase_04 AC 46 ms
26,304 KB
testcase_05 AC 228 ms
37,008 KB
testcase_06 AC 179 ms
36,752 KB
testcase_07 AC 30 ms
23,952 KB
testcase_08 AC 28 ms
23,952 KB
testcase_09 AC 2,594 ms
88,800 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;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.GetInt();
        int itemCount = inpt[0];
        int seiyakuCount = inpt[1];
        
        for(int i=0; i<seiyakuCount; i++) {
            this.SeiyakuList.Add(new Seiyaku(Reader.GetInt()));
        }
        List<int> targetNum = new List<int>();
        for(int i=0; i<itemCount; i++) {
            targetNum.Add(i);
        }
        List<List<int>> list = this.GetList(targetNum);
        int ans = 0;
        foreach (List<int> subList in list)
        {
            ans = Math.Max(ans, this.GetScore(subList));
        }
        Console.WriteLine(ans);
    }
    
    private int GetScore(List<int> target) {
        int ans = 0;
        foreach (Seiyaku se in this.SeiyakuList)
        {
            int idx1 = target.IndexOf(se.Before);
            int idx2 = target.IndexOf(se.After);
            if(idx1 < idx2) {
                ans += se.Point;
            }
        }
        return ans;
    }
    private List<List<int>> GetList(List<int> target) {
        List<List<int>> ans = new List<List<int>>();
        
        if(target.Count == 1) {
            List<int> num = new List<int>();
            num.Add(target[0]);
            ans.Add(num);
            return ans;
        }
        for(int i=0; i<target.Count; i++) {
            List<int> subList = new List<int>();
            subList.AddRange(target);
            subList.RemoveAt(i);
            List<List<int>> ret = this.GetList(subList);
            foreach (List<int> retSub in ret)
            {
                List<int> tmp = new List<int>();
                retSub.Add(target[i]);
                ans.Add(retSub);
            }
        }
        return ans;
    }
    private List<Seiyaku> SeiyakuList = new List<Seiyaku>();
    
    public class Seiyaku {
        public int Before;
        public int After;
        public int Point;
        
        public Seiyaku(int[] init) {
            this.Before = init[0];
            this.After = init[1];
            this.Point = init[2];
        }
    }

    public class Reader {
        private static String InitText = @"


4 9
0 1 1
0 2 2
0 3 3
1 2 4
1 3 5
2 3 6
3 2 100
2 1 100
1 0 100


        ";
        
        private static System.IO.StringReader sr = null;
        
        public static bool IsDebug = true;
        
        public static string ReadLine() {
            if(IsDebug) {
                if(sr == null) {
                    sr = new System.IO.StringReader(InitText.Trim());
                }
                return sr.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ') {
            string[] inpt = ReadLine().Split(delimiter);
            int[] ret = new int[inpt.Length];
            for(int i=0; i<inpt.Length; i++) {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0