結果
問題 | No.27 板の準備 |
ユーザー | 明智重蔵 |
提出日時 | 2015-08-02 19:13:52 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,433 bytes |
コンパイル時間 | 877 ms |
コンパイル使用メモリ | 119,024 KB |
実行使用メモリ | 31,784 KB |
最終ジャッジ日時 | 2024-07-18 00:49:12 |
合計ジャッジ時間 | 2,143 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
コンパイルメッセージ
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.Linq;class Program{static string InputPattern = "Input4";static List<string> GetInputList(){var WillReturn = new List<string>();if (InputPattern == "Input1") {WillReturn.Add("28 29 30 30");}else if (InputPattern == "Input2") {WillReturn.Add("2 3 7 15");}else if (InputPattern == "Input3") {WillReturn.Add("3 6 11 20");}else {string wkStr;while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);}return WillReturn;}//必要な板の長さの配列static int[] NeedLenArr;static void Main(){List<string> InputList = GetInputList();NeedLenArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();List<int[]> LenCombiArrList = DeriveLenCombiArrList(NeedLenArr.Max());int AnswerCnt = int.MaxValue;string AnswerItaCombi = "";foreach (int[] EachCombiArr in LenCombiArrList) {bool FoundAnswer;int MinItaCnt;DeriveNeedMinCnt(EachCombiArr, out FoundAnswer, out MinItaCnt);if (FoundAnswer == false) continue;if (AnswerCnt < MinItaCnt) continue;AnswerCnt = MinItaCnt;AnswerItaCombi = "";Array.ForEach(EachCombiArr, X => AnswerItaCombi += X.ToString() + ",");}Console.WriteLine(AnswerCnt);Console.WriteLine("ABCの板の長さは{0}", AnswerItaCombi);}//長さの組み合わせを求めるstatic List<int[]> DeriveLenCombiArrList(int pMaxLen){var WillReturn = new List<int[]>();for (int A = 1; A <= pMaxLen; A++) {for (int B = A; B <= pMaxLen; B++) {for (int C = B; C <= pMaxLen; C++) {var wkList = new int[] { A, B, C };int[] WillAdd = wkList.Distinct().ToArray();WillReturn.Add(WillAdd);}}}return WillReturn;}//4つの長さを満たす、最小の板の枚数を動的計画法で求めるstatic void DeriveNeedMinCnt(int[] pLenCombiArr, out bool pFoundAnswer,out int pMinItaCnt){//添字が長さの合計、値が最小の枚数int UB = NeedLenArr.Max();Nullable<int>[] ItaCntArr = new Nullable<int>[UB + 1];//初期設定ItaCntArr[0] = 0;foreach (int EachLen in pLenCombiArr) {for (int I = 0; I <= UB; I++) { //123ナップサックなのでリバースループしない//長さの和を求めるif (ItaCntArr[I] == null) continue;int wkSumLen = I + EachLen;if (wkSumLen > UB) break;//枚数の和を求めるint wkSumCnt = (ItaCntArr[I] ?? 0) + 1;//枚数の最小値で更新可能かを判定if (ItaCntArr[wkSumLen] == null|| ItaCntArr[wkSumLen] > wkSumCnt) {ItaCntArr[wkSumLen] = wkSumCnt;}}}pFoundAnswer = Array.TrueForAll(NeedLenArr, X => ItaCntArr[X] != null);pMinItaCnt = NeedLenArr.Sum(X => ItaCntArr[X] ?? 0);}}