Submission #1444312
Source Code Expand
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { public static void Main(string[] args) { new MainClass().solve(); } Scanner cin = new Scanner(); int n; int[] a; void solve() { n = cin.nextInt(); a = new int[n]; for (int i = 0; i < n;i++) a[i] = cin.nextInt(); int[] min = new int[n]; min[0] = 0; min[1] = Math.Abs(a[1] - a[0]); for (int i = 2; i < n;i++){ min[i] = Math.Min(min[i-2]+Math.Abs(a[i]-a[i-2]), min[i-1]+Math.Abs(a[i]-a[i-1])); } Console.WriteLine(min[n-1]); } class Scanner { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class Mathf { private int mod = 1000000007; public Mathf() { } public Mathf(int mod) { this.mod = mod; } public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) {if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod;} } } }
Submission Info
Submission Time | |
---|---|
Task | C - 柱柱柱柱柱 |
User | rui0422 |
Language | C# (Mono 4.6.2.0) |
Score | 100 |
Code Size | 2400 Byte |
Status | AC |
Exec Time | 53 ms |
Memory | 18912 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 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 | 21 ms | 11092 KB |
sample_02.txt | AC | 21 ms | 9044 KB |
sample_03.txt | AC | 21 ms | 11092 KB |
subtask1_01.txt | AC | 20 ms | 9172 KB |
subtask1_02.txt | AC | 21 ms | 9044 KB |
subtask1_03.txt | AC | 21 ms | 11092 KB |
subtask1_04.txt | AC | 53 ms | 14816 KB |
subtask1_05.txt | AC | 53 ms | 18912 KB |
subtask1_06.txt | AC | 52 ms | 14816 KB |
subtask1_07.txt | AC | 52 ms | 14816 KB |