結果
| 問題 | 
                            No.258 回転寿司(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             aketijyuuzou
                         | 
                    
| 提出日時 | 2024-10-12 23:55:43 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 36 ms / 2,000 ms | 
| コード長 | 2,894 bytes | 
| コンパイル時間 | 1,247 ms | 
| コンパイル使用メモリ | 116,040 KB | 
| 実行使用メモリ | 19,840 KB | 
| 最終ジャッジ日時 | 2024-10-12 23:55:52 | 
| 合計ジャッジ時間 | 7,862 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 67 | 
コンパイルメッセージ
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 = "InputX";
    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();
        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 2 3 4");
            //6
            //2 4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            WillReturn.Add("5 4 4 9");
            //14
            //1 4
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("7");
            WillReturn.Add("1 2 9 10 1 1 4");
            //16
            //2 4 7
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("1");
            WillReturn.Add("100");
            //100
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }
    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] VArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        int UB = VArr.GetUpperBound(0);
        //最大の美味しさ合計[添字]なDP表
        var DPArr = new Nullable<int>[UB + 1];
        //配るDPでの配布元の添字
        int[] MotoIndArr = new int[UB + 1];
        for (int I = 0; I <= UB; I++) MotoIndArr[I] = -1;
        DPArr[0] = VArr[0];
        if (UB > 0) DPArr[1] = VArr[1];
        for (int I = 0; I <= UB; I++) {
            Action<int> UpdateAct = (pNewInd) =>
            {
                if (pNewInd > UB) return;
                int NewVal = DPArr[I].Value + VArr[pNewInd];
                if (DPArr[pNewInd].HasValue == false
                 || DPArr[pNewInd].Value < NewVal) {
                    DPArr[pNewInd] = NewVal;
                    MotoIndArr[pNewInd] = I;
                }
            };
            UpdateAct(I + 2);
            UpdateAct(I + 3);
            //for (int J = 0; J <= UB; J++) {
            //    Console.WriteLine("DPArr[{0}]={1}", J, DPArr[J]);
            //}
        }
        //UBかUB-1が最大値
        int MaxSumVal = DPArr[UB].Value;
        int CurrInd = UB;
        if (UB > 0 && DPArr[UB - 1].Value > MaxSumVal) {
            MaxSumVal = DPArr[UB - 1].Value;
            CurrInd = UB - 1;
        }
        Console.WriteLine(MaxSumVal);
        //DPの経路復元
        var IndList = new List<int>();
        while (CurrInd != -1) {
            IndList.Add(CurrInd);
            CurrInd = MotoIndArr[CurrInd];
        }
        var sb = new System.Text.StringBuilder();
        for (int I = IndList.Count - 1; 0 <= I; I--) {
            sb.Append(IndList[I] + 1);
            if (I > 0) sb.Append(' ');
        }
        Console.WriteLine(sb.ToString());
    }
}
            
            
            
        
            
aketijyuuzou