結果
| 問題 |
No.15 カタログショッピング
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-31 14:08:38 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,177 bytes |
| コンパイル時間 | 2,218 ms |
| コンパイル使用メモリ | 107,008 KB |
| 実行使用メモリ | 439,616 KB |
| 最終ジャッジ日時 | 2024-10-02 08:25:50 |
| 合計ジャッジ時間 | 7,903 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 4 |
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int[] inpt = Reader.GetInt();
int itemCount = inpt[0];
this.MaxTotalPrice = inpt[1];
this.PriceList = new int[itemCount + 1];
List<int> indexList = new List<int>();
for(int i=1; i<=itemCount; i++) {
this.PriceList[i] = int.Parse(Reader.ReadLine());
indexList.Add(i);
}
List<String> ans = this.GetAns(1, MaxTotalPrice);
if(ans == null) {
Console.WriteLine("-1");
} else
{
foreach (string item in ans)
{
Console.WriteLine(item.Trim());
}
}
}
private Dictionary<int, Dictionary<int, List<String>>> dic = new Dictionary<int, Dictionary<int, List<string>>>();
private List<String> GetAns(int idx, int remain) {
if(!dic.ContainsKey(idx)) {
dic.Add(idx, new Dictionary<int, List<string>>());
}
if(dic[idx].ContainsKey(remain)) {
return dic[idx][remain];
}
if(remain == 0) {
List<string> ret = new List<string>();
ret.Add(string.Empty);
return ret;
}
if(remain < 0) {
return null;
}
if(idx >= this.PriceList.Length) {
return null;
}
List<string> ans = new List<string>();
List<string> subAns = null;
if(this.PriceList[idx] <= remain) {
subAns = this.GetAns(idx + 1, remain - this.PriceList[idx]);
if(subAns != null) {
foreach (string item in subAns)
{
ans.Add(idx + " " + item);
}
}
}
subAns = this.GetAns(idx + 1, remain);
if(subAns != null) {
ans.AddRange(subAns);
}
if(ans.Count == 0) {
ans = null;
}
this.dic[idx].Add(remain, ans);
return ans;
}
private int MaxTotalPrice = 0;
private int[] PriceList;
public class Reader {
private static String InitText = @"
3 220
180
220
280
";
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();
}
}
14番