Submission #1243754
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { new Calc().Solve(); return; } public class Calc { int[] dp; int N; public void Solve() { N = ReadLine<int>(); var a = ReadLine<int>(' '); dp = new int[N]; dp[0] = 0; dp[1] = Math.Abs(a[0] - a[1]); dp[2] = Math.Min(Math.Abs(a[0] - a[2]), Math.Abs(a[1] - a[2]) + dp[1]); for (int i = 3; i < N; i++) { dp[i] = Math.Min(dp[i - 1] + Math.Abs(a[i] - a[i - 1]), dp[i - 2] + Math.Abs(a[i] - a[i - 2])); } dp[N-1].WL(); } } public static T[] ReadLine<T>(params char[] separators) { return Console.ReadLine() .Split(separators) .Where(_ => _.Length > 0) .Select(_ => (T)Convert.ChangeType(_, typeof(T))) .ToArray(); } public static T ReadLine<T>() { return (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); } public static List<T> ReadLines<T>(int N) { List<T> rt = new List<T>(); for (int i = 0; i < N; i++) { T item = (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); rt.Add(item); } return rt; } } public static class Utils { public static void WL(this object obj) { Console.WriteLine(obj); } public static string Docking<T>(this IEnumerable<T> collection,Func<T,string> filter = null) { StringBuilder sb = new StringBuilder(); foreach (var item in collection) { string str = filter != null ? filter(item) : item.ToString(); sb.Append(str); } return sb.ToString(); } public static string RangeDocking<T>(this IEnumerable<T> collection, int start,int end,Func<T,string> filter = null) { if (start > collection.Count()) throw new IndexOutOfRangeException(); if (end < 0) throw new IndexOutOfRangeException(); StringBuilder sb = new StringBuilder(); for (int i = start; i < end; i++) { string str = filter != null ? filter(collection.ElementAt(i)) : collection.ElementAt(i).ToString(); sb.Append(str); } return sb.ToString(); } public static void WriteLineAll<T>(this IEnumerable<T> collection) { foreach (var item in collection) { item.WL(); } } }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | xztaityozx |
Language | C# (Mono 4.6.2.0) |
Score | 0 |
Code Size | 2337 Byte |
Status | RE |
Exec Time | 70 ms |
Memory | 23516 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 26 ms | 11604 KB |
sample_02.txt | AC | 25 ms | 11348 KB |
sample_03.txt | AC | 26 ms | 13396 KB |
subtask1_01.txt | RE | 24 ms | 10976 KB |
subtask1_02.txt | AC | 25 ms | 9428 KB |
subtask1_03.txt | AC | 26 ms | 13524 KB |
subtask1_04.txt | AC | 68 ms | 23516 KB |
subtask1_05.txt | AC | 67 ms | 21468 KB |
subtask1_06.txt | AC | 70 ms | 21468 KB |
subtask1_07.txt | AC | 68 ms | 21468 KB |