Submission #31695236


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks
{
    public class E
    {
        public static void Main()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<int>();
            var A = Scanner.ScanEnumerable<long>().ToArray();
            const long inf = (long)1e18;

            var answer = inf;
            for (var k = 0; k < 2; k++)
            {
                var dp = new long[N + 10, 2];
                if (k == 0)
                {
                    dp[1, 0] = 0;
                    dp[1, 1] = inf;
                }
                else
                {
                    dp[1, 0] = inf;
                    dp[1, 1] = A[0];
                }

                for (var i = 1; i < N; i++)
                {
                    dp[i + 1, 0] = dp[i, 1];
                    dp[i + 1, 1] = Math.Min(dp[i, 0], dp[i, 1]) + A[i];
                }

                if (k == 0) answer = Math.Min(answer, dp[N, 1]);
                else answer = Math.Min(answer, Math.Min(dp[N, 0], dp[N, 1]));
            }

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            public static string ScanLine() => Console.ReadLine()?.Trim() ?? string.Empty;
            public static string[] Scan() => ScanLine().Split(' ');
            public static T Scan<T>() where T : IConvertible => Convert<T>(Scan()[0]);
            public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]));
            }
            public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]));
            }
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]));
            }
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]));
            }
            public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
            {
                var line = Scan();
                return (Convert<T1>(line[0]), Convert<T2>(line[1]), Convert<T3>(line[2]), Convert<T4>(line[3]), Convert<T5>(line[4]), Convert<T6>(line[5]));
            }
            public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => Scan().Select(Convert<T>);
            private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
        }
    }
}

Submission Info

Submission Time
Task E - Takahashi and Animals
User AconCavy
Language C# (.NET Core 3.1.201)
Score 500
Code Size 3730 Byte
Status AC
Exec Time 148 ms
Memory 71888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 78 ms 27892 KiB
001.txt AC 144 ms 71864 KiB
002.txt AC 79 ms 27848 KiB
003.txt AC 73 ms 27900 KiB
004.txt AC 131 ms 67440 KiB
005.txt AC 139 ms 67608 KiB
006.txt AC 135 ms 60328 KiB
007.txt AC 123 ms 56572 KiB
008.txt AC 141 ms 71888 KiB
009.txt AC 136 ms 66112 KiB
010.txt AC 86 ms 35452 KiB
011.txt AC 125 ms 61496 KiB
012.txt AC 105 ms 42492 KiB
013.txt AC 128 ms 60604 KiB
014.txt AC 139 ms 71220 KiB
015.txt AC 141 ms 71568 KiB
016.txt AC 141 ms 71348 KiB
017.txt AC 140 ms 71716 KiB
018.txt AC 136 ms 71524 KiB
019.txt AC 143 ms 71444 KiB
020.txt AC 148 ms 71356 KiB
021.txt AC 139 ms 71192 KiB
022.txt AC 139 ms 71248 KiB
023.txt AC 141 ms 71252 KiB
example0.txt AC 91 ms 28024 KiB
example1.txt AC 73 ms 27900 KiB