結果

問題 No.1077 Noelちゃんと星々4
ユーザー Lily89164763Lily89164763
提出日時 2020-06-12 21:30:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 2,447 bytes
コンパイル時間 2,813 ms
コンパイル使用メモリ 106,648 KB
実行使用メモリ 60,404 KB
最終ジャッジ日時 2023-09-06 09:50:45
合計ジャッジ時間 6,131 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,696 KB
testcase_01 AC 61 ms
21,708 KB
testcase_02 AC 120 ms
48,140 KB
testcase_03 AC 134 ms
54,060 KB
testcase_04 AC 89 ms
33,704 KB
testcase_05 AC 83 ms
31,128 KB
testcase_06 AC 94 ms
34,804 KB
testcase_07 AC 98 ms
38,928 KB
testcase_08 AC 91 ms
32,656 KB
testcase_09 AC 87 ms
31,036 KB
testcase_10 AC 135 ms
56,048 KB
testcase_11 AC 112 ms
43,680 KB
testcase_12 AC 104 ms
39,744 KB
testcase_13 AC 81 ms
28,748 KB
testcase_14 AC 135 ms
55,192 KB
testcase_15 AC 103 ms
41,232 KB
testcase_16 AC 94 ms
33,124 KB
testcase_17 AC 109 ms
41,504 KB
testcase_18 AC 137 ms
56,768 KB
testcase_19 AC 82 ms
28,288 KB
testcase_20 AC 60 ms
21,700 KB
testcase_21 AC 144 ms
60,404 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using CompLib.Util;

public class Program
{
    private const int MaxY = 10000;

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int[] y = sc.IntArray();


        var dp = new int[(n + 1) * (MaxY + 1)];
        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= MaxY; j++)
            {
                dp[C(i, j)] = int.MaxValue;
            }
        }

        dp[C(0, 0)] = 0;

        for (int i = 1; i <= n; i++)
        {
            int min = int.MaxValue;
            for (int j = 0; j <= MaxY; j++)
            {
                min = Math.Min(min, dp[C(i - 1, j)]);
                dp[C(i, j)] = min + Math.Abs(y[i - 1] - j);
            }
        }

        int ans = int.MaxValue;
        for (int i = 0; i <= MaxY; i++)
        {
            ans = Math.Min(ans, dp[C(n, i)]);
        }

        Console.WriteLine(ans);
    }

    int C(int i, int j)
    {
        return i * (MaxY + 1) + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}
0