結果

問題 No.664 超能力者Aと株価予測
ユーザー バカらっくバカらっく
提出日時 2018-03-09 23:52:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,182 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 110,208 KB
実行使用メモリ 28,032 KB
最終ジャッジ日時 2024-04-19 04:15:49
合計ジャッジ時間 8,763 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
24,832 KB
testcase_01 AC 31 ms
19,328 KB
testcase_02 AC 33 ms
19,200 KB
testcase_03 AC 31 ms
19,072 KB
testcase_04 AC 32 ms
19,200 KB
testcase_05 AC 31 ms
19,328 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split().Select(a => int.Parse(a)).ToArray();

        int openTime = inpt[0];
        int maxCount = inpt[1];

        long syojikin = inpt[2];

        Kabuka = new int[openTime + 1];
        State st = State.Even;
        for (int i = 0; i <= openTime; i++) {
            Kabuka[i] = int.Parse(Reader.ReadLine());
            if(i>0) {
                if(Kabuka[i]>Kabuka[i-1]) {
                    if (st == State.Even)
                    {
                        Tani.Add(0);
                    } else if(st == State.Kudari) {
                        Tani.Add(i - 1);
                    }
                    st = State.Nobori;
                } else if(Kabuka[i]<Kabuka[i-1]) {
                    if(st == State.Even) {
                        Yama.Add(0);
                    } else {
                        Yama.Add(i - 1);
                    }
                    st = State.Kudari;
                }
                if(i == openTime) {
                    if(st == State.Nobori) {
                        Yama.Add(i);
                    } else if(st == State.Kudari) {
                        Tani.Add(i);
                    }
                }
            }
        }

        long ans = GetAns(0, syojikin, maxCount);
        Console.WriteLine(ans);
    }

    private long GetAns(int idx, long money, int remain) {
        long ans = money;
        if(remain <= 0) {
            return money;
        }
        if(idx >=Kabuka.Length) {
            return money;
        }
        if(!Tani.Any(a=>a>=idx)) {
            return money;
        }
        int kai = Tani.First(a => a >= idx);
        if(!Yama.Any(a=>a>kai)) {
            return money;
        }
        int uri = Yama.First(a => a > kai);
        long kabu = money / Kabuka[kai];
        long zan = money - (kabu * Kabuka[kai]);
        zan += Kabuka[uri] * kabu;
        ans = Math.Max(ans, GetAns(uri + 1, zan, remain - 1));

        ans = Math.Max(ans, GetAns(kai + 1, money, remain));
        return ans;
    }

    int[] Kabuka;
    private List<int> Yama = new List<int>();
    private List<int> Tani = new List<int>();

    private enum State {
        Nobori,
        Kudari,
        Even,
    }


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



21 5 3000
150
144
133
130
127
129
138
142
131
131
126
126
133
135
121
115
122
130
124
110
138
134


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0