結果
| 問題 | No.54 Happy Hallowe'en |
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-05 20:24:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,676 bytes |
| 記録 | |
| コンパイル時間 | 1,026 ms |
| コンパイル使用メモリ | 113,920 KB |
| 実行使用メモリ | 433,152 KB |
| 最終ジャッジ日時 | 2024-10-04 01:58:25 |
| 合計ジャッジ時間 | 8,032 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 14 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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
";
}
14番