結果
| 問題 |
No.1077 Noelちゃんと星々4
|
| コンテスト | |
| ユーザー |
Lily89164763
|
| 提出日時 | 2020-06-12 21:30:30 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 2,000 ms |
| コード長 | 2,447 bytes |
| コンパイル時間 | 2,224 ms |
| コンパイル使用メモリ | 114,820 KB |
| 実行使用メモリ | 63,928 KB |
| 最終ジャッジ日時 | 2024-06-24 04:29:26 |
| 合計ジャッジ時間 | 4,577 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
Lily89164763