結果

問題 No.54 Happy Hallowe'en
ユーザー 14番14番
提出日時 2016-04-05 20:24:25
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,676 bytes
コンパイル時間 4,205 ms
コンパイル使用メモリ 111,084 KB
実行使用メモリ 439,232 KB
最終ジャッジ日時 2024-04-14 22:10:11
合計ジャッジ時間 11,163 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
24,308 KB
testcase_01 AC 34 ms
24,372 KB
testcase_02 AC 33 ms
24,692 KB
testcase_03 AC 32 ms
22,076 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

public class Program
{
    public void Proc(){
        Reader.IsDebug = false;
        int ieCount = int.Parse(Reader.ReadLine());
        this.OkasiList = new int[ieCount];
        this.LimitList = new int[ieCount];
        
        List<int> targetList = new List<int>();
        for(int i=0; i<ieCount; i++) {
            int[] inpt = Reader.GetInt();
            this.OkasiList[i] = inpt[0];
            this.LimitList[i] = inpt[1];
            targetList.Add(i);
        }
        
        long ans = this.GetAns(0, targetList);
        Console.WriteLine(ans);
    }
    
    Dictionary<int, Dictionary<string, long>> dic = new Dictionary<int, Dictionary<string, long>>();
    private long GetAns(int havOkashi, List<int> target) {
        string key = string.Join<int>("#", target);
        if(!dic.ContainsKey(havOkashi)) {
            dic.Add(havOkashi, new Dictionary<string, long>());
        }
        if(dic[havOkashi].ContainsKey(key)) {
            return dic[havOkashi][key];
        }
        if(target.Count == 1) {
            if(this.LimitList[target[0]] > havOkashi) {
                return this.OkasiList[target[0]];
            } else
            {
                return 0;
            }
        }
        
        long ans = 0;
        for(int i=0; i<target.Count; i++) {
            int idx = target[i];
            if(LimitList[idx] > havOkashi) {
                List<int> subList = new List<int>();
                subList.AddRange(target);
                subList.RemoveAt(i);
                ans = Math.Max(ans, this.GetAns(havOkashi + OkasiList[idx], subList) + OkasiList[idx]);
            }
        }
        dic[havOkashi].Add(key, ans);
        return ans;
    }
    
    public int[] OkasiList;
    public int[] LimitList;

    
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.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;
    }
    
    private static string initStr = @"



2
1 3
100 2



";
}

0