結果

問題 No.357 品物の並び替え (Middle)
ユーザー 14番14番
提出日時 2016-05-28 03:18:24
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,469 bytes
コンパイル時間 1,077 ms
コンパイル使用メモリ 113,480 KB
実行使用メモリ 27,244 KB
最終ジャッジ日時 2024-04-16 18:01:08
合計ジャッジ時間 2,656 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
19,456 KB
testcase_01 AC 33 ms
19,200 KB
testcase_02 AC 34 ms
19,072 KB
testcase_03 AC 34 ms
19,200 KB
testcase_04 AC 34 ms
19,712 KB
testcase_05 AC 34 ms
19,328 KB
testcase_06 AC 34 ms
19,200 KB
testcase_07 AC 34 ms
19,456 KB
testcase_08 AC 35 ms
19,328 KB
testcase_09 RE -
testcase_10 AC 39 ms
19,696 KB
testcase_11 RE -
testcase_12 AC 80 ms
19,712 KB
testcase_13 AC 56 ms
19,580 KB
testcase_14 AC 52 ms
19,424 KB
testcase_15 RE -
testcase_16 AC 43 ms
19,308 KB
testcase_17 AC 39 ms
19,320 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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        ItemCount = inpt[0];
        int inputCount = inpt[1];
        
        for(int i=0; i<inputCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            if(!pointDic.ContainsKey(inpt[1])) {
                pointDic.Add(inpt[1], new Dictionary<int,long>());
            }
            pointDic[inpt[1]].Add(inpt[0], inpt[2]);
        }
        long ans = this.GetAns(0, this.ItemCount);
        Console.WriteLine(ans);
    }
    
    private int ItemCount = 0;
    
    private Dictionary<int, long> dic = new Dictionary<int, long>();
    private long GetAns(int flag, int remain) {
        if(dic.ContainsKey(flag)) {
            return dic[flag];
        }
        if(remain == 0) {
            return 0;
        }
        long ans = 0;
        for(int i=0; i<ItemCount; i++) {
            int key =  1<<i;
            if((flag & key) == key) {
                continue;
            }
            long p = 0;
            foreach (int tmp in pointDic[i].Keys)
            {
                int subKey = 1<<tmp;
                if((flag & subKey) == subKey) {
                    p+=pointDic[i][tmp];
                }
            }
            long ret = this.GetAns(flag + key, remain - 1);
            ret += p;
            ans = Math.Max(ans, ret);
        }
        dic.Add(flag, ans);
        return ans;
    } 
    
    private Dictionary<int, Dictionary<int, long>> pointDic = new Dictionary<int, Dictionary<int, long>>();
    



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



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 string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0