Submission #15438755


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class MPCO2020D
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            var N = RI();
            var A = RIa(N);

            long amount = 1000;
            long nstock = 0;
            for (int d = 0; d < N; ++d)
            {                
                if (nstock == 0)
                {
                    for (int nd = d; nd < N; ++nd)
                    {
                        if (A[nd + 1] > A[nd])
                        {   // nd に買う
//                            Console.WriteLine($"L:{nd} {A[nd]} * {amount / A[nd]} {amount} -> {amount % A[nd]}");
                            nstock = amount / A[nd];
                            amount = amount % A[nd];
                            d = nd;
                            break;
                        }
                    }
                }
                else
                {
                    for (int nd = d; nd < N + 1; ++nd)
                    {
                        if (A[nd + 1] < A[nd])
                        {   // nd に売る
//                            Console.WriteLine($"S:{nd} {A[nd]} * {nstock} {amount} -> {amount + nstock * A[nd]}");
                            amount += nstock * A[nd];
                            nstock = 0;
                            d = nd;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(amount);

#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
            Console.WriteLine();
#endif
        }

        static int RI()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] RIa(int n)
        {
            string[] sa = Console.ReadLine().Split(' ');
            int[] la = new int[n + 1];
            for (int i = 0; i < n; ++i)
            {
                la[i] = int.Parse(sa[i]);
            }
            la[n] = int.MinValue;
            return la;
        }
    }
}

Submission Info

Submission Time
Task D - Road to Millionaire
User miyakosis
Language C# (.NET Core 3.1.201)
Score 400
Code Size 2386 Byte
Status AC
Exec Time 97 ms
Memory 27528 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status AC
AC × 21
Set Name Test Cases
Sample
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-random-01.txt, 01-random-02.txt, 01-random-03.txt, 01-random-04.txt, 01-random-05.txt, 01-random-06.txt, 01-random-07.txt, 01-random-08.txt, 01-random-09.txt, 01-random-10.txt, 02-increasing-01.txt, 03-decreasing-01.txt, 04-large-01.txt, 04-large-02.txt, 04-large-03.txt, 05-maximum-01.txt, 05-maximum-02.txt, 05-maximum-03.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 80 ms 26972 KiB
00-sample-02.txt AC 86 ms 27320 KiB
00-sample-03.txt AC 87 ms 27176 KiB
01-random-01.txt AC 89 ms 27080 KiB
01-random-02.txt AC 91 ms 27172 KiB
01-random-03.txt AC 83 ms 27148 KiB
01-random-04.txt AC 79 ms 27132 KiB
01-random-05.txt AC 96 ms 27152 KiB
01-random-06.txt AC 86 ms 27096 KiB
01-random-07.txt AC 77 ms 27216 KiB
01-random-08.txt AC 97 ms 27152 KiB
01-random-09.txt AC 72 ms 27368 KiB
01-random-10.txt AC 89 ms 27148 KiB
02-increasing-01.txt AC 82 ms 27076 KiB
03-decreasing-01.txt AC 86 ms 27092 KiB
04-large-01.txt AC 88 ms 27244 KiB
04-large-02.txt AC 81 ms 27528 KiB
04-large-03.txt AC 89 ms 27112 KiB
05-maximum-01.txt AC 92 ms 27044 KiB
05-maximum-02.txt AC 97 ms 27128 KiB
05-maximum-03.txt AC 82 ms 27132 KiB